|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2012-05-29 00:23 UTC] 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
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Dec 06 03:00:01 2025 UTC |
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}\";");