> Atm it isn't possible to use a construct like $var = ${'_GET'}; inside a
> function or method. Will this behaviour change in future versions of
> PHP? I think it is somehow odd and inconsistent to not be able to use
> the superglobals that way, while it is possible outside of functions and
> methods and also with any other variable, e.g. the $HTTP_*_VARS.
> Imo it's an unnecessary restriction and will keep ppl using the old
> $HTTP_*_VARS. I also see no reason for it to stay that way and i think
> it wasn't intended by you, the developers, in the first place but turned
> out to work that way afterwards.
> So I really hope it'll change, would make much more sense. What do you
> think?
>
It comes down to how autoglobals are resolved.
When a script containg $_GET is parsed, ZE says "Oh, _GET is a registered
autoglobal, I'll flag that for fetching from the global symbol table".
Important factoid here: The target hashtable is resolved at compile time.
All other variable lookups (not entirely true, but run with me here) are
resolved at run-time roughly thus:
Check (hashtable) for (expression)
In the case of $foo these break down as:
Check (active_symbol_table) for ('foo' index)
In the case of $bar['foo'] they become:
Check (Check (active_symbole_table) for ('bar' index')) for ('foo' index)
So in order for ZE to resolve the autoglobals correctly during runtime it
has to ask two questions for every *part* of every variable resolution: "Are
we checking against the active symbol table? Is the index we're looking for
in the autoglobal registry?" If so, replace active_symbol_table with the
global symbol_table, otherwise do the lookup as normal.
Putting this extra bundle of steps completely negates the speed-benefit of
resolving autoglobals at compile time.
Given that, I certainly wouldn't hold my breath waiting for that
functionality to change.
-Sara
P.S. - This is why:
$a['b']['c']['d']['e']['f'][] = 1;
$a['b']['c']['d']['e']['f'][] = 2;
$a['b']['c']['d']['e']['f'][] = 3;
$a['b']['c']['d']['e']['f'][] = 4;
is slower than:
$b = &$a['b']['c']['d']['e']['f'];
$b[] = 1;
$b[] = 2;
$b[] = 3;
$b[] = 4;
Since in the first example the engine is doing 24 hash table lookups as
opposed to 11 in the second example.
And yes, $a['b']['c']['d']['e']['f'] = range(1,4); would be even faster....
it's called an example :p
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php