PHP Parse error: syntax error, unexpected T_SL

chris (2010-02-09 07:56:17)
23463 views
5 replies

This is a hard one to spot, so I thought it would be worth posting up here in the hope that it will save somebody some time. The PHP error looks like this:

PHP Parse error:  syntax error, unexpected T_SL in 

One of the things that I regularly whinge at my team in Yahoo! about is meaningful log messages. It really doesn't make sense to log an error if it isn't clear what is being communicated, or what possible course of action an engineer/developer might take to resolve the problem.

PHP commonly slips up on this point. There are even cases of errors being logged in Hebrew! In order for an error message to be useful, it should be a) Tagged in some way so that monitoring systems can be hooked into it, and b) it should bear some meaningful information for whoever is likely to read the message.

In this case, the fix is simple. The message is probably complaining about a trailing whitespace on the end of a HEREDOC declaration. For exmaple, if your heredoc looks like this:

$html = <<<EOT
   <div>here is some html</div>
EOT;

Then you should check after the first 'EOT' to see if there is some whitespace immediately after it.


christo
Digg it! Submit to Slashdot Add to Blinklist Del.icio.us Add to Newsvine Add to Technorati Add it to Google Bookmarks
comment
Fawaz
2010-07-18 13:32:30

Thanks dude

This is a hard one to spot, so I thought it would be worth posting up here in the hope that it will save somebody some time. The PHP error looks like this:

PHP Parse error:  syntax error, unexpected T_SL in 

One of the things that I regularly whinge at my team in Yahoo! about is meaningful log messages. It really doesn't make sense to log an error if it isn't clear what is being communicated, or what possible course of action an engineer/developer might take to resolve the problem.

PHP commonly slips up on this point. There are even cases of errors being logged in Hebrew! In order for an error message to be useful, it should be a) Tagged in some way so that monitoring systems can be hooked into it, and b) it should bear some meaningful information for whoever is likely to read the message.

In this case, the fix is simple. The message is probably complaining about a trailing whitespace on the end of a HEREDOC declaration. For exmaple, if your heredoc looks like this:

$html = <<<EOT
   <div>here is some html</div>
EOT;

Then you should check after the first 'EOT' to see if there is some whitespace immediately after it.


christo




<p>
Thank you very much for your suggestion.. it really worked. there must not be whitespaces after that.
Thanks
</p>
reply icon
Prateek Sharma
2012-01-31 17:39:41

Thanks Dude! You Saved My Day

Thanks For this aid. It really helped and saved my day. The logs should be meaningful. How the hell you come to know about this error.
reply icon
Daniel
2011-10-18 19:57:39

Thanks!
reply icon
anonymous
2011-12-11 21:45:05


$html = <<<EOT
   <div>here is some html</div>
EOT;

Then you should check after the first 'EOT' to see if there is some whitespace immediately after it.


christo

Can also happen when the HEREDOC not correctly defind.
$html = <<EOT
   <div>here is some html</div>
EOT;
reply icon
Ricki Rocker
2011-11-08 16:53:34

I know late but some useful info also

5.3 has introduced NOWDOC following the same format except that the delimiter is surrounded by single quotes eg.

$string = <<< 'ENCLOSED'
blah blah
ENCLOSED;

print $string;

what's good about this? well NOWDOC treats everything like a string without the requirement for escaping anything (similar to CDATA in XML)

(great new for me when treating xml documents themselves as strings)
reply icon