[php-src] PR #23251: PFA: Fix magic method resolution
| From: | arnaud-lb | Date: | Thu, 13 Aug 2026 15:40:40 +0000 |
| Subject: | [php-src] PR #23251: PFA: Fix magic method resolution | ||
| Groups: | php.git-pulls | ||
| Request: | Send a blank email to git-pulls+get-37825@lists.php.net to get a copy of this message | ||
Pull Request: https://github.com/php/php-src/pull/23251
Author: arnaud-lb
We conveniently use the function's scope for the scope of generated PFA closures as this allows
const exprs referencing
self:: or parent:: to behave normally:
However this affects method resolution for magic methods:
```
class C {
private static function priv($a) {}
public static function __call($name, $args) {}
}
// Sees only C::__call()
$f = C::priv(?);
// Generates the following closure with scope=C:
$f = function ($arguments0) {
// Sees C::priv()
static::priv($arguments0);
};
```
Fix by using the actual scope for PFAs of magic methods.
This should be enough as long as the generated closure doesn't inherit any self::
or parent:: expression from the magic method. Currently that's the case. If this
changes we may have to rewrite these expressions, which I would like to avoid as this increases
complexity and maintenance overhead.
The test magic_scope.phpt demonstrates the issue. default_arg_scope.phpt
just checks relative-class resolution in default argument values.
Bug found by Ryan @ Calif.io