Edit report at http://bugs.php.net/bug.php?id=53666&edit=1

 ID:                 53666
 Updated by:         cataphr...@php.net
 Reported by:        crystal at cyclonephp dot com
-Summary:            local static variables in methods handled
                     incorrectly
+Summary:            local static variables in methods tied to the object
                     instance
 Status:             Open
-Type:               Bug
+Type:               Feature/Change Request
 Package:            Scripting Engine problem
 Operating System:   linux
 PHP Version:        5.3.4
 Block user comment: N
 Private report:     N

 New Comment:

Why? At most this is a (bc breaking) feature request. Function static
variables have always been tied only with the function itself.


Previous Comments:
------------------------------------------------------------------------
[2011-01-06 12:40:16] crystal at cyclonephp dot com

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




------------------------------------------------------------------------



-- 
Edit this bug report at http://bugs.php.net/bug.php?id=53666&edit=1

Reply via email to