Req #55493 [Com]: Superglobal variable variables with ${expression} in non-global scope
| From: | vovan-ve at yandex dot ru | Date: | Wed, 24 Aug 2011 10:21:23 +0000 |
| Subject: | Req #55493 [Com]: Superglobal variable variables with ${expression} in non-global scope | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-162901@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=55493&edit=1
ID: 55493
Comment by: vovan-ve at yandex dot ru
Reported by: vovan-ve at yandex dot ru
Summary: Superglobal variable variables with ${expression} in
non-global scope
Status: Assigned
Type: Feature/Change Request
Package: Variables related
Operating System: Windows XP SP3
PHP Version: 5.3.7
Assigned To: dmitry
Block user comment: N
Private report: N
New Comment:
When I tried to obfuscate a part of code I was surprised by this strange behariour. Of course,
current implementation is correct on the one hand. But on the other hand the situation looks funny:
this way is allowad, and this too, but this is not.
Previous Comments:
------------------------------------------------------------------------
[2011-08-24 04:11:14] laruence@php.net
sure, it can be fixed by decide target symbol table again in the execution time
for not const OPs,
but I don't think this is really necessary . :)
------------------------------------------------------------------------
[2011-08-23 18:16:12] kalle@php.net
This still seems a little strange that we cannot pick the correct symbol table at compile time, all
it should need would be a check to see if the compiled value is matching one thats a super global.
I remember to have encountered something similar a while back, which I'm not sure if I reported
or not, but def. something we should look into at some point.
Dmitry, can you clarify this?
------------------------------------------------------------------------
[2011-08-23 16:49:00] laruence@php.net
As I said, this is a limitation of PHP design, so mark as won't fix.
Thank you for your interest in PHP.
------------------------------------------------------------------------
[2011-08-23 16:22:46] laruence@php.net
when fetching a variable, the target symbol table is decided in compiling time,
for the script above, in compiling time, only const string "_SERVER" can be
took consider as a SUPERVAR and assign the global symbol table as
target_symbol_table.
the others
varname only can be see in execution time, so Zend VM think it
should be fetched from a local symbol table.
and the 'local symbol table' for the global scope statement is actual 'global
symbol table', therefor it works 'as expected'.
------------------------------------------------------------------------
[2011-08-23 14:14:42] vovan-ve at yandex dot ru
Description:
------------
ONLY Superglobal variable variables does not work ONLY in non-global
scope and ONLY with non-constant expression. See test script.
I found Req 38527, but it does not describe the problem properly and
due to misunderstanding it has status Feature Request instead of Bug
(and also it is too old).
Test script:
---------------
// in global scope everything is right
$name = '_SERVER';
var_dump(
isset(${'_SERVER'}),
isset($$name),
isset(${$name}),
isset(${'_SER' . 'VER'}),
isset(${'na' . 'me'})
);
echo PHP_EOL;
// but outside of global scope there is a trouble
function f() {
$name = '_SERVER';
var_dump(
isset(${'_SERVER'}),
isset($$name),
isset(${$name}),
isset(${'_SER' . 'VER'}),
isset(${'na' . 'me'})
);
}
f();
Expected result:
----------------
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)
Actual result:
--------------
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)
bool(false)
bool(false)
bool(false)
bool(true)
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=55493&edit=1