Page 1 of 1

PLease clarify T_STRING error meaning

Posted: Wed Aug 21, 2002 10:56 am
by rfigley
As I'm developing this site. (Learning as I go) I get a number of repeating errors as I test my code which I don't understand. One of which is unexpected or expected T_STRING..... What is a T_STRING? I'm guessing this is a syntax error, but understading it better would be helpul.

Thanks

Posted: Wed Aug 21, 2002 11:00 am
by nielsene
Can you post the full error message and the source code for the line its appearing on? (The first occurence is probably the most useful for debugging if the error occurs multiple times.)

Posted: Wed Aug 21, 2002 11:36 am
by protokol
Often times this occurs when you have this scenario:

$me = array('first_name' => 'Bob');
echo "Hello there, my name is $me['first_name']";

This will produce that same error that you encountered. There are 2 ways to fix it:

echo "Hello there, my name is {$me['first_name']}";

OR

echo "Hello there, my name is ".$me['first_name'];

I prefer the first method, but both will work.

Posted: Wed Aug 21, 2002 12:20 pm
by llimllib
yeah, I always get this message when I forget to put braces around an array variable in a double-quoted string.