|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2005-04-27 12:48 UTC] sniper@php.net
[2005-04-27 18:19 UTC] justinpatrin@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Oct 24 08:00:01 2025 UTC |
Description: ------------ When setting a static variable by reference (as one would want to do in PHP4 since the object model uses copies instead of references) the static variable becomes non-static and is lost when the function ends. I assume this could be fixed by making the reference itself static instead of the variable. This can also be "fixed" by using a container as the static variable (an array or object) and setting the var by ref within the array/object. $v[0] =& $var; or $v->v =& $var; I also tested this in PHP 5.0.4 and the same thing happens. I realize that PHP5 uses refs instead of copies by default. Reproduce code: --------------- function a() { static $v; $a = 0; if (!isset($v)) { $v =& $a; echo 'setting v<br/> '; } } a(); a(); function b() { static $w; $a = 0; if (!isset($w)) { $w = $a; echo 'setting w<br/> '; } } b(); b(); Expected result: ---------------- setting v setting w Actual result: -------------- setting v setting v setting w