[php-src] PR #23254: Fix array_map optimization with non-literal function or non-literal args
| From: | arnaud-lb | Date: | Thu, 13 Aug 2026 15:54:30 +0000 |
| Subject: | [php-src] PR #23254: Fix array_map optimization with non-literal function or non-literal args | ||
| Groups: | php.git-pulls | ||
| Request: | Send a blank email to git-pulls+get-37828@lists.php.net to get a copy of this message | ||
Pull Request: https://github.com/php/php-src/pull/23254
Author: arnaud-lb
Non-literal expressions must be evaluated once and memoized to maintain semantics:
``` php
$callback = function ($value) {
global $callback;
$callback = function () { return 'changed'; };
return $value + 1;
};
array_map($callback, [1,2]);
// Expected result: [2,3]
// Actual result: [2,'changed']
```
Unfortunately, we can't memoize pre-bound PFA arguments without breaking pass-by-reference, so
we disable the optimization if the callback is a PFA with non-literal arguments. We could improve
this when the function is known and we can determine that the argument is not passed by ref.
Bug found by Ryan @ Calif.io.