Bug #71950 [Nab]: static variables are incorrect after call parent::method()

From: Date: Sat, 09 Apr 2016 08:28:42 +0000
Subject: Bug #71950 [Nab]: static variables are incorrect after call parent::method()
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-200448@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=71950&edit=1 ID: 71950 User updated by: mika018 at gmail dot com Reported by: mika018 at gmail dot com Summary: static variables are incorrect after call parent::method() Status: Not a bug Type: Bug Package: Class/Object related Operating System: Windows 10 64 PHP Version: Irrelevant Block user comment: N Private report: N New Comment: Ok thank you My test was distorted because of "a" method is the A class construct too. Sorry, my bad Previous Comments: ------------------------------------------------------------------------ [2016-04-03 22:19:44] requinix@php.net Thank you for taking the time to write to us, but this is not a bug. Please double-check the documentation available at http://www.php.net/manual/ and the instructions on how to report a bug at http://bugs.php.net/how-to-report.php Static variables will persist their values across every call. *Every* call. ------------------------------------------------------------------------ [2016-04-03 18:18:46] mika018 at gmail dot com Description: ------------ When you call parent::method() and there is a static variable in this, the value returned to all inherited objects is the same Test script: --------------- class A { function a() { static $i; if (!$i) { $i = $this->value; } return $i; } } class B extends A { public $value = 'B'; } class C extends A { public $value = 'C'; function a() { return parent::a(); } } $b = new B; echo $b->a(); $c = new C; echo $c->a(); Expected result: ---------------- BC Actual result: -------------- BB ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=71950&edit=1

« previous php.bugs (#200448) next »