|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2017-03-02 11:48 UTC] requinix@php.net
-Summary: Local static variable not update after create new
object of class
+Summary: static (variables) docs do not explain behavior in
class methods
-Type: Bug
+Type: Documentation Problem
[2017-03-02 11:48 UTC] requinix@php.net
[2017-03-02 12:24 UTC] cca dot alexk at gmail dot com
[2017-03-02 12:43 UTC] requinix@php.net
[2017-03-10 17:59 UTC] cmb@php.net
-Status: Open
+Status: Verified
[2017-03-10 17:59 UTC] cmb@php.net
|
|||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Nov 02 09:00:01 2025 UTC |
Description: ------------ Steps to reproduce: 1. Create object of class with method with local static variable 2. Assign value to this local variable 3. Create new object of that class 4. Check value of this variable Test script: --------------- <?php class Foo { protected $bar; public function __construct($bar) { $this->bar = $bar; } public function bar() { return $this->foo(); } public function foo() { static $bar; if (!$bar) { $bar = $this->bar; } return $bar; } } var_dump((new Foo(123))->bar()); var_dump((new Foo(456))->bar()); Expected result: ---------------- int(123) int(456) Actual result: -------------- int(123) int(123)