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
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
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

Add a Patch

Pull Requests

Add a Pull Request

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-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 01:01:28 2024 UTC