php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #12278 variable variable inside a string
Submitted: 2001-07-20 08:15 UTC Modified: 2002-06-02 14:09 UTC
From: dardo at uol dot com dot ar Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 4.0.6 OS: independant
Private report: No CVE-ID: None
 [2001-07-20 08:15 UTC] dardo at uol dot com dot ar
<?php
$foo1="nonsense";
$foo2="foo1";
print "$$foo2";
?>

THIS programs output $foo2, (IS THIS OK??)

<?php
$foo1="nonsense";
$foo2="foo1";
print "{$$foo2}";
?>

this program outputs nonsense (THIS IS CORRECT)

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2001-07-20 14:14 UTC] zak@php.net
Are you sure that the output of:

<?php
$foo1="nonsense";
$foo2="foo1";
print "$$foo2";
?>

is: $foo2

Under PHP 4.0.6 (Win2k and Linux) the script generates $foo1 when I run it.

From looking at the parser, this does not seem to be an error - at most just an omission.

Perhaps one of the developers could comment? I don't know if the behavior needs to be changed or just documented.

I would **guess** that we could extend the lexer to handle this by adding something like:

<ST_DOUBLE_QUOTES,ST_BACKQUOTE,ST_HEREDOC>"$$" {
	yy_push_state(ST_LOOKING_FOR_VARNAME);
	return T_VARIABLE;
}

However, I have not tested it and really have no idea what I am doing! :)
 [2002-06-02 14:09 UTC] derick@php.net
Sorry, but the bug system is not the appropriate forum for asking
support questions. Your problem does not imply a bug in PHP itself.
For a list of more appropriate places to ask for help using PHP,
please visit http://www.php.net/support.php

Thank you for your interest in PHP.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Apr 23 06:01:30 2024 UTC