-
Notifications
You must be signed in to change notification settings - Fork 8.1k
PFA: Fix magic method resolution #23251
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
arnaud-lb
wants to merge
1
commit into
php:master
Choose a base branch
from
arnaud-lb:pfa-bug-2
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| --TEST-- | ||
| PFA default argument value scope | ||
| --ENV-- | ||
| A=1 | ||
| --FILE-- | ||
| <?php | ||
|
|
||
| if (getenv('A')) { | ||
| /* Relative class references are never resolved at compile time on traits */ | ||
| trait T { | ||
| static function f($a, $b = self::VAL) { | ||
| var_dump($b); | ||
| } | ||
| } | ||
| trait U { | ||
| static function g($a, $b = parent::VAL) { | ||
| var_dump($b); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| class C { | ||
| const VAL = 'C'; | ||
| use T; | ||
| } | ||
|
|
||
| class D extends C { | ||
| const VAL = 'D'; | ||
| use U; | ||
| } | ||
|
|
||
| C::f(0); | ||
| D::f(0); | ||
| C::f(?, ...)(0); | ||
| D::f(?, ...)(0); | ||
|
|
||
| D::g(0); | ||
| D::g(?, ...)(0); | ||
|
|
||
| ?> | ||
| --EXPECT-- | ||
| string(1) "C" | ||
| string(1) "C" | ||
| string(1) "C" | ||
| string(1) "C" | ||
| string(1) "C" | ||
| string(1) "C" | ||
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -31,7 +31,7 @@ echo (string) new ReflectionFunction($bar); | |
| $bar(100); | ||
| ?> | ||
| --EXPECTF-- | ||
| Closure [ <user> static public method {closure:%s:%d} ] { | ||
| Closure [ <user> static function {closure:%s:%d} ] { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 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): |
||
| @@ %s 10 - 10 | ||
|
|
||
| - Parameters [1] { | ||
|
|
@@ -42,7 +42,7 @@ Foo::method | |
| int(1) | ||
| Foo::method | ||
| int(1) | ||
| Closure [ <user> static public method {closure:%s:%d} ] { | ||
| Closure [ <user> static function {closure:%s:%d} ] { | ||
| @@ %s 17 - 17 | ||
|
|
||
| - Parameters [2] { | ||
|
|
@@ -55,7 +55,7 @@ int(10) | |
| Foo::method | ||
| int(10) | ||
| int(20) | ||
| Closure [ <user> static public method {closure:%s:%d} ] { | ||
| Closure [ <user> static function {closure:%s:%d} ] { | ||
| @@ %s 24 - 24 | ||
|
|
||
| - Bound Variables [1] { | ||
|
|
||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| --TEST-- | ||
| Magic method scope | ||
| --CREDITS-- | ||
| Ryan @ Calif.io | ||
| --FILE-- | ||
| <?php | ||
|
|
||
| class InstanceTarget | ||
| { | ||
| private function secret(string $value): void | ||
| { | ||
| echo "PRIVATE-INSTANCE:$value\n"; | ||
| } | ||
|
|
||
| public function __call(string $name, array $arguments): void | ||
| { | ||
| echo "MAGIC-INSTANCE:$name:" . implode(',', $arguments) . "\n"; | ||
| } | ||
| } | ||
|
|
||
| class StaticTarget | ||
| { | ||
| private static function secret(string $value): void | ||
| { | ||
| echo "PRIVATE-STATIC:$value\n"; | ||
| } | ||
|
|
||
| public static function __callStatic(string $name, array $arguments): void | ||
| { | ||
| echo "MAGIC-STATIC:$name:" . implode(',', $arguments) . "\n"; | ||
| } | ||
| } | ||
|
|
||
| $instance = new InstanceTarget(); | ||
|
|
||
| $instance->secret('direct'); | ||
| StaticTarget::secret('direct'); | ||
|
|
||
| $instancePartial = $instance->secret(?); | ||
| $staticPartial = StaticTarget::secret(?); | ||
| $instancePartial('controlled'); | ||
| $staticPartial('controlled'); | ||
|
|
||
| ?> | ||
| --EXPECT-- | ||
| MAGIC-INSTANCE:secret:direct | ||
| MAGIC-STATIC:secret:direct | ||
| MAGIC-INSTANCE:secret:controlled | ||
| MAGIC-STATIC:secret:controlled |
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
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
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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.