|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2006-04-11 22:15 UTC] karoly at negyesi dot net
Description:
------------
The code has been tested on PHP 4.3, 4.4, 5.0 and 5.1 various minors.
Reproduce code:
---------------
function storage($key) {
static $storage = array('a' => array('x', 'y'));
return $storage[$key];
static $storage = array('x', 'y'); // comment this out to see expected result
}
var_dump(storage('a'));
Expected result:
----------------
array(2) {
[0]=>
string(1) "x"
[1]=>
string(1) "y"
}
Actual result:
--------------
NULL
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Nov 19 12:00:02 2025 UTC |
It's the same as <?php exit; class Test { } ?> The class will be still declared, even though there is an exit statement before the declaration. It doesn't mean that it's "executed", because there is a big difference between "execution" and "compilation".If static variables are resolved in compile time then <?php function storage($key) { return $storage; static $storage = array('a' => array('x', 'y')); } var_dump(storage('a')); ?> should give an expected result.