|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2011-01-07 21:52 UTC] cataphract@php.net
-Summary: local static variables in methods handled incorrectly
+Summary: local static variables in methods tied to the object
instance
-Type: Bug
+Type: Feature/Change Request
[2011-01-07 21:52 UTC] cataphract@php.net
[2011-01-07 22:13 UTC] crystal at cyclonephp dot com
[2011-11-13 21:24 UTC] normandiggs at gmail dot com
[2018-03-15 11:48 UTC] cmb@php.net
-Status: Open
+Status: Suspended
[2018-03-15 11:48 UTC] cmb@php.net
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2026 The PHP GroupAll rights reserved. |
Last updated: Mon Jan 05 02:00:02 2026 UTC |
Description: ------------ The inital value of a static variable in a non-static method should take care about the current instance. The initialization should be done when a method of the instance is called, and not only when the method is first called in the script. The local static variable should be interpreted as an object variable that is visible only in the declaring method. Test script: --------------- <?php class StatTest { function statvartest() { static $var = 'initial'; echo $var."\n"; if ($var == 'initial') { $var = 'changed'; } } } $testA = new StatTest; $testA->statvartest(); $testA->statvartest(); $testB = new StatTest; $testB->statvartest(); $testB->statvartest(); Expected result: ---------------- initial changed initial changed Actual result: -------------- initial changed changed changed