[GIT-PULLS] [php-src] PR #23254: Fix array_map optimization with non-literal function or non-literal args
[email protected] (arnaud-lb)
| Newsgroups | php.git-pulls |
|---|---|
| Message-ID | <[email protected]> |
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.