[GIT-PULLS] [php-src] PR #23251: PFA: Fix magic method resolution

[email protected] (arnaud-lb)
Newsgroups php.git-pulls
Message-ID <[email protected]>
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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.