PFA: Fix magic method resolution - #23251
Conversation
Girgias
left a comment
There was a problem hiding this comment.
I can't see any problems with this.
One question: would resolving self/parent at compile time for traits remove the possible concern about needing to rewrite?
As I cannot see this really being a problem with an unbound closure being partially applied. But maybe I'm missing something.
| <?php | ||
|
|
||
| if (getenv('A')) { | ||
| /* Relative class references are never resolved at compile time on traits */ |
There was a problem hiding this comment.
Well, I was trying to resolve them at one point, but was hitting issues with the JIT. So I guess this might be revisited at one point.
| ?> | ||
| --EXPECTF-- | ||
| Closure [ <user> static public method {closure:%s:%d} ] { | ||
| Closure [ <user> static function {closure:%s:%d} ] { |
There was a problem hiding this comment.
This matches more what:
<?php
class C {
private static function priv($a) { echo "private priv\n"; }
public static function __callStatic($name, $args) { echo "trampoline $name\n"; }
public static function foo() {}
}
// Sees only C::__callStatic()
$f = C::priv(...);
echo (string) new ReflectionFunction($f);
$g = C::foo(...);
echo (string) new ReflectionFunction($g);produces (although that output is also a bit confusing):
Closure [ <internal> static public method priv ] {
- Parameters [1] {
Parameter #0 [ <optional> mixed ...$arguments ]
}
}
Closure [ <user> static public method foo ] {
@@ /in/AItpa 6 - 6
}
Yes, if |
We conveniently use the function's scope for the scope of the generated closure as this allows const exprs referencing self:: or parent:: to behave normally. However this affects method resolution for magic methods. Fix by using the actual scope for PFAs of magic methods.
Might be worthwhile to spend some time again on it and try to resolve the JIT issues. |
We conveniently set the scope of generate PFA closures to the function's scope as this allows const exprs referencing
self::orparent::to behave normally:However this affects method resolution for magic methods:
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::orparent::expression from the magic method. Currently that's the case. If this changes we may need to rewrite these expressions, which I would like to avoid as this increases complexity and maintenance overhead a bit.The test
magic_scope.phptdemonstrates the issue.default_arg_scope.phptjust checks relative-class resolution in default argument values.Bug found by Ryan @ Calif.io