Skip to content

[deprecation] Deprecate DeprecatedAnnotationToDeprecatedAttributeRector and ConstAndTraitDeprecatedAttributeRector - #8347

Merged
TomasVotruba merged 1 commit into
mainfrom
deprecate-deprecated-attribute-rules
Aug 12, 2026
Merged

[deprecation] Deprecate DeprecatedAnnotationToDeprecatedAttributeRector and ConstAndTraitDeprecatedAttributeRector#8347
TomasVotruba merged 1 commit into
mainfrom
deprecate-deprecated-attribute-rules

Conversation

@TomasVotruba

Copy link
Copy Markdown
Member

The #[Deprecated] attribute triggers a runtime deprecation, while the @deprecated annotation is a static hint only. Those have a different purpose and are not interchangeable, so converting one into the other is not a safe upgrade path - it changes application behavior at runtime.

Let phpstan/phpstan-deprecation-rules report the annotation instead.

What the rules did

+#[\Deprecated(message: 'Use SomeOtherFunction instead', since: '1.0.0')]
 function someFunction()
 {
 }
-
-/**
- * @deprecated 1.0.0 Use SomeOtherFunction instead
- */

The @deprecated annotation stays readable in the IDE and in static analysis, without emitting E_USER_DEPRECATED on every call.

Changes

  • DeprecatedAnnotationToDeprecatedAttributeRector and ConstAndTraitDeprecatedAttributeRector implement DeprecatedInterface and throw on refactor()
  • removed from all sets - ConstAndTraitDeprecatedAttributeRector is dropped from config/set/php85.php
  • tests and the shared DeprecatedAnnotationToDeprecatedAttributeConverter service are deleted

Side fix

The ForeachToArray*Rector test configs did not pin phpVersion(), and relied on the PHP version leaked by the removed test config that ran right before them. They now pin PhpVersion::PHP_84 explicitly.

…or and ConstAndTraitDeprecatedAttributeRector

The #[Deprecated] attribute triggers a runtime deprecation, while the
@deprecated annotation is a static hint only. Those serve a different
purpose and are not interchangeable, so converting one to the other is
not a safe upgrade path.

Use "phpstan/phpstan-deprecation-rules" to report the annotation instead.

Both rules are removed from all sets, their tests and the shared
DeprecatedAnnotationToDeprecatedAttributeConverter service are deleted.

Pin phpVersion in the ForeachToArray* test configs, as they relied on
the PHP version leaked by the removed test config.
@TomasVotruba
TomasVotruba enabled auto-merge (squash) August 12, 2026 05:49
@TomasVotruba
TomasVotruba merged commit d39693f into main Aug 12, 2026
52 checks passed
@TomasVotruba
TomasVotruba deleted the deprecate-deprecated-attribute-rules branch August 12, 2026 05:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant