[php-src] Issue #13607: Values on array properties on $this are not available to anonymous function are they have mutated

From: Date: Wed, 06 Mar 2024 11:08:34 +0000
Subject: [php-src] Issue #13607: Values on array properties on $this are not available to anonymous function are they have mutated
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-246520@lists.php.net to get a copy of this message
Issue: https://github.com/php/php-src/issues/13607 Author: alexpott ### Description The following code: ```php <?php class A { public $cache = [ 'a' => -1, 'b' => -1, 'c' => 0, ]; function sort () { uksort($this->cache, function ($a, $b) { return $this->cache[$a] <=> $this->cache[$b]; }); var_export($this->cache); } } $a = new A(); $a->sort(); $a->cache['d'] = -2; $a->sort(); ``` Resulted in this output: ``` array ( 'a' => -1, 'b' => -1, 'c' => 0, ) Warning: Undefined array key "a" in /in/LjhEX on line 12 Warning: Undefined array key "b" in /in/LjhEX on line 12 Warning: Undefined array key "b" in /in/LjhEX on line 12 Warning: Undefined array key "c" in /in/LjhEX on line 12 Warning: Undefined array key "c" in /in/LjhEX on line 12 Warning: Undefined array key "d" in /in/LjhEX on line 12 array ( 'a' => -1, 'b' => -1, 'c' => 0, 'd' => -2, ) ``` But I expected this output instead: ``` array ( 'a' => -1, 'b' => -1, 'c' => 0, )array ( 'd' => -2, 'a' => -1, 'b' => -1, 'c' => 0, ) ``` See https://3v4l.org/LjhEX and https://3v4l.org/9VVKU ### PHP Version PHP 8.3.3 ### Operating System _No response_

« previous php.bugs (#246520) next »