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

 ID:                 53666
 User updated by:    crystal at cyclonephp dot com
 Reported by:        crystal at cyclonephp dot com
 Summary:            local static variables in methods tied to the object
                     instance
 Status:             Open
 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:

Because this way local static variables can't be used eg. for caching
method 

return values. I think it's a very important use case. I also don't
think that it 

would cause severe bc issues.


Previous Comments:
------------------------------------------------------------------------
[2011-01-07 21:52:18] cataphr...@php.net

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

------------------------------------------------------------------------
[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