From:             
Operating system: linux
PHP version:      5.3.4
Package:          Scripting Engine problem
Bug Type:         Bug
Bug description:local static variables in methods handled incorrectly

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 bug report at http://bugs.php.net/bug.php?id=53666&edit=1
-- 
Try a snapshot (PHP 5.2):            
http://bugs.php.net/fix.php?id=53666&r=trysnapshot52
Try a snapshot (PHP 5.3):            
http://bugs.php.net/fix.php?id=53666&r=trysnapshot53
Try a snapshot (trunk):              
http://bugs.php.net/fix.php?id=53666&r=trysnapshottrunk
Fixed in SVN:                        
http://bugs.php.net/fix.php?id=53666&r=fixed
Fixed in SVN and need be documented: 
http://bugs.php.net/fix.php?id=53666&r=needdocs
Fixed in release:                    
http://bugs.php.net/fix.php?id=53666&r=alreadyfixed
Need backtrace:                      
http://bugs.php.net/fix.php?id=53666&r=needtrace
Need Reproduce Script:               
http://bugs.php.net/fix.php?id=53666&r=needscript
Try newer version:                   
http://bugs.php.net/fix.php?id=53666&r=oldversion
Not developer issue:                 
http://bugs.php.net/fix.php?id=53666&r=support
Expected behavior:                   
http://bugs.php.net/fix.php?id=53666&r=notwrong
Not enough info:                     
http://bugs.php.net/fix.php?id=53666&r=notenoughinfo
Submitted twice:                     
http://bugs.php.net/fix.php?id=53666&r=submittedtwice
register_globals:                    
http://bugs.php.net/fix.php?id=53666&r=globals
PHP 4 support discontinued:          http://bugs.php.net/fix.php?id=53666&r=php4
Daylight Savings:                    http://bugs.php.net/fix.php?id=53666&r=dst
IIS Stability:                       
http://bugs.php.net/fix.php?id=53666&r=isapi
Install GNU Sed:                     
http://bugs.php.net/fix.php?id=53666&r=gnused
Floating point limitations:          
http://bugs.php.net/fix.php?id=53666&r=float
No Zend Extensions:                  
http://bugs.php.net/fix.php?id=53666&r=nozend
MySQL Configuration Error:           
http://bugs.php.net/fix.php?id=53666&r=mysqlcfg

Reply via email to