php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #62175 single quotes vs double quotes give different results with token_get_all
Submitted: 2012-05-29 00:23 UTC Modified: 2012-05-29 08:53 UTC
From: iam4webwork at hotmail dot com Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: Irrelevant OS:
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: iam4webwork at hotmail dot com
New email:
PHP Version: OS:

 

 [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

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-05-29 00:54 UTC] anon at anon dot anon
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}\";");
 [2012-05-29 08:53 UTC] johannes@php.net
-Status: Open +Status: Not a bug
 [2012-05-29 08:53 UTC] johannes@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php


 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed Jul 02 10:01:38 2025 UTC