Bug #75474 [NEW]: function scope static variables are not bound to a unique function

From: Date: Thu, 02 Nov 2017 08:59:04 +0000
Subject: Bug #75474 [NEW]: function scope static variables are not bound to a unique function
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-212405@lists.php.net to get a copy of this message
From: nobots dot nospam at example dot org Operating system: PHP version: Irrelevant Package: *General Issues Bug Type: Bug Bug description:function scope static variables are not bound to a unique function Description: ------------ Every time a closure is generated from a named function, it creates a copy of the static variables rather than modifying the original named function's ones. function bar($k, $v){ static $foo = []; $foo[$k] = $v; return $foo; } var_dump(bar(0, 0)); var_dump(Closure::fromCallable("bar")(1, 1)); var_dump(bar(2, 2)); var_dump(Closure::fromCallable("bar")(3, 3)); $RF = new ReflectionFunction("bar"); var_dump($RF->getClosure()(4, 4)); var_dump(bar(5, 5)); the result after the last bar() call should be [0,1,2,3,4,5] but it is [0 => 0, 2 => 2, 5 => 5] essentially Closure::fromCallable() and $RF->getClosure() should always return the same Closure object: assert(Closure::fromCallable("foo") === Closure::fromCallable("foo")); assert($RF->getClosure() === $RF->getClosure()); assert(Closure::fromCallable("foo") === $RF->getClosure()); Unless they are rebound to a different $this or cloned. Thanks -- Edit bug report at https://bugs.php.net/bug.php?id=75474&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=75474&r=trysnapshot54 Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=75474&r=trysnapshot55 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=75474&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=75474&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=75474&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=75474&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=75474&r=needscript Try newer version: https://bugs.php.net/fix.php?id=75474&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=75474&r=support Expected behavior: https://bugs.php.net/fix.php?id=75474&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=75474&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=75474&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=75474&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=75474&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=75474&r=dst IIS Stability: https://bugs.php.net/fix.php?id=75474&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=75474&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=75474&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=75474&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=75474&r=mysqlcfg

« previous php.bugs (#212405) next »