Skip to content

docs: deprecated attribute support and compatibility matrix#185

Open
vinceAmstoutz wants to merge 1 commit intophpstan:2.0.xfrom
vinceAmstoutz:patch-1
Open

docs: deprecated attribute support and compatibility matrix#185
vinceAmstoutz wants to merge 1 commit intophpstan:2.0.xfrom
vinceAmstoutz:patch-1

Conversation

@vinceAmstoutz
Copy link
Copy Markdown

@vinceAmstoutz vinceAmstoutz commented May 6, 2026

Cover PHP 8.4 native #[\Deprecated] attribute detection (via the phpstan/phpstan-deprecation-rules extension, not PHPStan core) and add a compatibility table summarising which mechanisms emit a runtime deprecation and which are caught by PHPStan.

Cover PHP 8.4 native #[\Deprecated] attribute detection (via the extension, not PHPStan core) and add a compatibility table summarising which mechanisms emit a runtime deprecation and which are caught by PHPStan.
@vinceAmstoutz
Copy link
Copy Markdown
Author

vinceAmstoutz commented May 6, 2026

@ondrejmirtes I tested in a project and the #[\Deprecated] attribute works perfectly with phpstan/phpstan-deprecation-rules, but unfortunately it's not documented. I hope this PR will help.

@ondrejmirtes
Copy link
Copy Markdown
Member

My first impression here is that this addition to the README is completely unnecessary.

The Deprecated attribute isn't really usable, it's only allowed above functions, methods and only most recently above traits.

@vinceAmstoutz
Copy link
Copy Markdown
Author

The current README only mentions @deprecated annotations, so users have no way to know that PHP 8.4's #[\Deprecated] attribute is also supported by the extension.
And even if the attribute currently only works on functions, methods and traits, I don't see why that makes it not worth documenting.

When I presented this extension at a talk, a Symfony core team member directly asked me whether trigger_deprecation() was detected — which shows the confusion is real. Documenting that #[\Deprecated] works and trigger_deprecation() doesn't would save that question from being asked repeatedly.

WDYT?

@vinceAmstoutz
Copy link
Copy Markdown
Author

ping @mtarld

@ondrejmirtes
Copy link
Copy Markdown
Member

Fair, but I'd reword it. I don't entirely agree with the framing. the fact that trigger_deprecation is not detected is a direct consequence of https://phpstan.org/user-guide/troubleshooting-types#what-phpstan-doesn%E2%80%99t-do.

Detection of #[\Deprecated] is provided by this extension

That's kind of half-true. PHPStan itself reads this attribute and propagates it into various isDeprecated method implementations in its reflection API. So in theory you don't need to install phpstan-deprecation-rules and you can write your own rules or Restricted Usage Extensions that would ask reflection objects about isDeprecated().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants