Bug #81686 [NEW]: Method static variables stored across different instances

From: Date: Wed, 01 Dec 2021 16:56:51 +0000
Subject: Bug #81686 [NEW]: Method static variables stored across different instances
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-238097@lists.php.net to get a copy of this message
From: norrisjibril at gmail dot com Operating system: MacOs PHP version: 8.1.0 Package: *General Issues Bug Type: Bug Bug description:Method static variables stored across different instances Description: ------------ When this is run on PHP8.0 and older (7.x), the static $cache variable is set to [] on each instantiation but on 8.1 it still keeps the data from the previous instantiations. PHP8.1 test link https://3v4l.org/qLpoT#v8.1rc3 PHP7.4 test link https://3v4l.org/qLpoT#v7.4.26 <?php abstract class Cache{ protected function put($key,$value){ static $cache = []; var_dump($cache); return $cache[$key] = $value; } } $instance1 = new class extends Cache{ public function store($key,$value) { return $this->put($key,$value); } }; $instance1->store("one",1); $instance1->store("two",2); $instance1->store("three",3); $instance2 = new class extends Cache{ public function store($key,$value) { return $this->put($key,$value); } }; $instance2->store("four",4); $instance2->store("five",5); $instance3 = new class extends Cache{ public function store($key,$value) { return $this->put($key,$value); } }; $instance3->store("six",6); $instance3->store("seven",7); -- Edit bug report at https://bugs.php.net/bug.php?id=81686&edit=1 -- Fix committed: https://bugs.php.net/fix.php?id=81686&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=81686&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=81686&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=81686&r=needscript Try newer version: https://bugs.php.net/fix.php?id=81686&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=81686&r=support Expected behavior: https://bugs.php.net/fix.php?id=81686&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=81686&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=81686&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=81686&r=globals PHP version support discontinued: https://bugs.php.net/fix.php?id=81686&r=phptooold Daylight Savings: https://bugs.php.net/fix.php?id=81686&r=dst IIS Stability: https://bugs.php.net/fix.php?id=81686&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=81686&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=81686&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=81686&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=81686&r=mysqlcfg

« previous php.bugs (#238097) next »