PFA: Fix magic method resolution - #23251
Open
arnaud-lb wants to merge 1 commit into
Open
Conversation
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.
Girgias
approved these changes
Aug 14, 2026
Girgias
left a comment
Member
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 */ |
Member
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} ] { |
Member
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
}
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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