|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2005-12-13 10:52 UTC] tomas_matousek at hotmail dot com
Description:
------------
PHP lexer omits end-of-line characters following T_END_HEREDOC token. This also causes incorrect output of highlight_string() function.
Reproduce code:
---------------
$code = '
<?
$x = <<<EOT
some string
EOT
$y = 2;
?>';
display_tokens(token_get_all($code));
highlight_string($code);
function display_tokens($tokens)
{
foreach ($tokens as $token)
{
if (is_array($token))
{
echo token_name($token[0]),"\n";
echo $token[0]," '",htmlentities(addcslashes($token[1],"\n\r\t")),"'\n";
}
else
{
echo " '",htmlentities($token),"'\n";
}
}
}
Expected result:
----------------
T_INLINE_HTML
311 '\r\n'
T_OPEN_TAG
367 '<?'
T_WHITESPACE
370 ' \r\n '
T_VARIABLE
309 '$x'
T_WHITESPACE
370 ' '
'='
T_WHITESPACE
370 ' '
T_START_HEREDOC
371 '<<<EOT\r\n'
T_STRING
307 'some'
T_ENCAPSED_AND_WHITESPACE
314 ' '
T_STRING
307 'string'
T_ENCAPSED_AND_WHITESPACE
314 ' \r\n'
T_END_HEREDOC
372 'EOT'
T_WHITESPACE
370 '\r\n ' // '\r\n' is missing in actual result
T_VARIABLE
309 '$y'
T_WHITESPACE
370 ' '
'='
T_WHITESPACE
370 ' '
T_LNUMBER
305 '2'
';'
T_WHITESPACE
370 '\r\n'
T_CLOSE_TAG
369 '?>'
<?
$x = <<<EOT
some string
EOT $y = 2;
?>
Actual result:
--------------
T_INLINE_HTML
311 '\r\n'
T_OPEN_TAG
367 '<?'
T_WHITESPACE
370 ' \r\n '
T_VARIABLE
309 '$x'
T_WHITESPACE
370 ' '
'='
T_WHITESPACE
370 ' '
T_START_HEREDOC
371 '<<<EOT\r\n'
T_STRING
307 'some'
T_ENCAPSED_AND_WHITESPACE
314 ' '
T_STRING
307 'string'
T_ENCAPSED_AND_WHITESPACE
314 ' \r\n'
T_END_HEREDOC
372 'EOT' // missing '\r\n'
T_WHITESPACE
370 ' '
T_VARIABLE
309 '$y'
T_WHITESPACE
370 ' '
'='
T_WHITESPACE
370 ' '
T_LNUMBER
305 '2'
';'
T_WHITESPACE
370 '\r\n'
T_CLOSE_TAG
369 '?>'
<?
$x = <<<EOT
some string
EOT $y = 2;
?>
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Oct 25 08:00:01 2025 UTC |
The same result with latest snapshot. The problem is probably here (file zend_language_scanner.l, around line 1750): if (unput_semicolon) { unput(';'); } I would suggest to replace unputting with yyless(label_len); which would preserve both ';' and {NEWLINE}.