Edit report at https://bugs.php.net/bug.php?id=62175&edit=1
ID: 62175
Comment by: anon at anon dot anon
Reported by: iam4webwork at hotmail dot com
Summary: single quotes vs double quotes give different
results with token_get_all
Status: Open
Type: Bug
Package: Scripting Engine problem
PHP Version: Irrelevant
Block user comment: N
Private report: N
New Comment:
You forgot to escape the $, so the variable got substituted into the string
before tokens_get_all even saw it. Should be:
$tokens = token_get_all("<?php \"{\$bar}\";");
Previous Comments:
------------------------------------------------------------------------
[2012-05-29 00:23:26] iam4webwork at hotmail dot com
Description:
------------
$tokens = token_get_all('<?php "{$bar}";');
vs.
$tokens = token_get_all("<?php \"{$bar}\";");
Test script:
---------------
$tokens = token_get_all('<?php "{$bar}";');
foreach ($tokens as $token) if (is_array($token)) print token_name($token[0])
."\n";
echo '<P>';
$bar = 'bar'; // to avoid error notice
$tokens = token_get_all("<?php \"{$bar}\";");
foreach ($tokens as $token) if (is_array($token)) print token_name($token[0])
."\n";
Expected result:
----------------
T_OPEN_TAG
T_CURLY_OPEN
T_VARIABLE
T_OPEN_TAG
T_CURLY_OPEN
T_VARIABLE
Actual result:
--------------
T_OPEN_TAG
T_CURLY_OPEN
T_VARIABLE
in the 2nd case got this instead:
T_OPEN_TAG
T_CONSTANT_ENCAPSED_STRING
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=62175&edit=1