0

In PHP why is this a syntax error:

$row['some_key'] = "kkkk";

Raises

Parse error: syntax error, unexpected T_STRING

From the documentation I understood this to be perfectly valid PHP, yet it throws the same error every time (and the error of course goes away then I comment the line out).

Edit: After long searching I actually noticed that the file is indeed corrupted in some way. In Vim (on ubuntu 12.04) the file looks just normal. But when viewing from other computers it's corrupted. So not related to PHP.

5
  • 3
    Check previous rows for a missing semi-colon Commented Aug 1, 2012 at 14:05
  • 1
    did you declare $row as an array? Commented Aug 1, 2012 at 14:05
  • Duplicate of stackoverflow.com/questions/9792197/… Commented Aug 1, 2012 at 14:06
  • it doesnt error for me at all. It looks perfectly valid to me. Maybe if we can see the whole script we might be able to help out whats causing it. Usually a missing semi colon or somethign before this bit fo code. Commented Aug 1, 2012 at 14:06
  • Could you add the rest of the code, some lines before and after. Commented Aug 1, 2012 at 14:07

1 Answer 1

1

In PHP why is this a syntax error:

It's not. If you're getting unexpected T_STRING, the problem is elsewhere (hint: look at the line above).

Sign up to request clarification or add additional context in comments.

2 Comments

And when I comment this line out, shouldn't the upper line then throw the error (which it does not)?
@Guu not necessarily. It's going to throw an error when it sees something it doesn't know what to do with. The line above it is probably valid, too. Are you sure you aren't missing a semicolon?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.