-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Implement GH-12908: Show attribute name/class in ReflectionAttribute … #12917
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -764,6 +764,8 @@ class ReflectionAttribute implements Reflector | |
/** @cvalue REFLECTION_ATTRIBUTE_IS_INSTANCEOF */ | ||
public const int IS_INSTANCEOF = UNKNOWN; | ||
|
||
public string $name; | ||
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. Should be readonly? 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. Perhaps, although the others aren't. The readonly-ness is handled manually by 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. I also think this should be possible because changing the property makes zero sense, and makes no difference. Some people may naively think that the name property has an effect on the attribute itself. TBH we also made a few properties readonly in the past, so I think it's doable now as well, unless some very popular library (e.g. BetterReflection) redefine them. 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. OK, I'll check BetterReflection some time later and if that's okay I'll drop the special handling and let these use 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. Here is the patch to remove the special handling: https://gist.github.com/nielsdos/e69d6b826fecf60a7c3fedce3f83ff7f However, we can't apply that patch. BetterReflection relies on the behaviour (e.g. Roave/BetterReflection@3eedf48 but there are more cases, also exception classes in |
||
|
||
public function getName(): string {} | ||
public function getTarget(): int {} | ||
public function isRepeated(): bool {} | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
--TEST-- | ||
GH-12908 (Show attribute name/class in ReflectionAttribute dump) | ||
--FILE-- | ||
<?php | ||
|
||
#[\AllowDynamicProperties, \Foo] | ||
class Test { | ||
} | ||
|
||
print_r((new ReflectionClass(Test::class))->getAttributes()); | ||
|
||
?> | ||
--EXPECT-- | ||
Array | ||
( | ||
[0] => ReflectionAttribute Object | ||
( | ||
[name] => AllowDynamicProperties | ||
) | ||
|
||
[1] => ReflectionAttribute Object | ||
( | ||
[name] => Foo | ||
) | ||
|
||
) |
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.
why is this needed and not in b0e83aa?
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.
Because there is already code that copies into the property table for the case you linked.
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.
My commit got reverted, I missed the fact that the property is inherited from
ReflectionFunctionAbstract
.