Req #53666 [Opn->Sus]: local static variables in methods tied to the object instance

From: Date: Thu, 15 Mar 2018 11:48:36 +0000
Subject: Req #53666 [Opn->Sus]: local static variables in methods tied to the object instance
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-214369@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=53666&edit=1 ID: 53666 Updated by: cmb@php.net Reported by: crystal at cyclonephp dot com Summary: local static variables in methods tied to the object instance -Status: Open +Status: Suspended 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: > Please, fix it. It's very weird behavior. In my opinion, tying *static* variables to *dynamic* object instances would be rather surprising. Furthermore considering the BC break, this feature certainly would require the RFC process[1]. Anybody is welcome to start it! For the time being I'm suspending this ticket. [1] <https://wiki.php.net/rfc/howto> Previous Comments: ------------------------------------------------------------------------ [2011-11-13 21:24:50] normandiggs at gmail dot com Please, fix it. It's very weird behavior. Another one example: http://codepad.viper-7.com/jKkwzF ------------------------------------------------------------------------ [2011-01-07 22:13:04] crystal at cyclonephp dot com 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. ------------------------------------------------------------------------ [2011-01-07 21:52:18] cataphract@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 https://bugs.php.net/bug.php?id=53666&edit=1

« previous php.bugs (#214369) next »