Skip to content

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

Closed
wants to merge 2 commits into from

Conversation

nielsdos
Copy link
Member

@nielsdos nielsdos commented Dec 9, 2023

…dump

This is consistent with how many other Reflection classes have a name field, and it makes debugging easier.

…te dump

This is consistent with how many other Reflection classes have a name
field, and it makes debugging easier.
@nielsdos nielsdos marked this pull request as ready for review December 9, 2023 20:38
@nielsdos nielsdos requested a review from kocsismate as a code owner December 9, 2023 20:38
@nielsdos nielsdos linked an issue Dec 9, 2023 that may be closed by this pull request
@@ -764,6 +764,8 @@ class ReflectionAttribute implements Reflector
/** @cvalue REFLECTION_ATTRIBUTE_IS_INSTANCEOF */
public const int IS_INSTANCEOF = UNKNOWN;

public string $name;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be readonly?

Copy link
Member Author

Choose a reason for hiding this comment

The 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 _reflection_write_property and it throws a ReflectionException. So for consistency I went this route.
The readonly modifier makes it throw an Error, so changing the behaviour of the others would be a small BC break.

Copy link
Member

Choose a reason for hiding this comment

The 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.

Copy link
Member Author

Choose a reason for hiding this comment

The 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 readonly

Copy link
Member Author

Choose a reason for hiding this comment

The 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 catch would be required to change) and that patch therefore causes 562 test failures.

@nielsdos nielsdos requested a review from iluuu1994 as a code owner December 9, 2023 21:24
@@ -1122,6 +1122,7 @@ static void reflection_attribute_factory(zval *object, HashTable *attributes, ze
reference->target = target;
intern->ptr = reference;
intern->ref_type = REF_TYPE_ATTRIBUTE;
ZVAL_STR_COPY(reflection_prop_name(object), data->name);
Copy link
Contributor

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?

Copy link
Member Author

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.

Copy link
Member

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.

@nielsdos nielsdos closed this in 3b5986d Feb 4, 2024
nicolas-grekas added a commit to symfony/symfony that referenced this pull request Mar 12, 2024
This PR was merged into the 5.4 branch.

Discussion
----------

[VarDumper] Fix test suite with PHP 8.4

| Q             | A
| ------------- | ---
| Branch?       | 5.4
| Bug fix?      | no
| New feature?  | no
| Deprecations? | no
| Issues        | Fix #54180
| License       | MIT

Lately, attribute name has been added to `ReflectionAttribute`, which makes messed up with the CI a bit with PHP 8.4. Here is the PR: php/php-src#12917

We can change the current virtual dump property to some "real" one by adding `name` in the caster when it doesn't exist yet. If it already exists, we're running PHP 8.4 or later. This way we avoid having different tests with the different PHP versions.

Should we add something in `ReflectionCaster` to remember to remove this part when the minimal PHP version Symfony requires is >= 8.4 ? If yes, what would be the best "syntax"?

Commits
-------

94426aa [VarDumper] Fix test suite with PHP 8.4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Show attribute name/class in ReflectionAttribute dump
4 participants