{"record":{"id":"85b2c83ec4cc8ece","repo":"rectorphp/rector","slug":"s-rule-is-deprecated-as-the-deprecated-attr-85b2c8","errorCode":null,"errorMessage":"\"%s\" rule is deprecated, as the #[Deprecated] attribute triggers a runtime deprecation, unlike the @deprecated annotation; use \"phpstan/phpstan-deprecation-rules\" to report the annotation instead","messagePattern":"\"(.+?)\" rule is deprecated, as the #\\[Deprecated\\] attribute triggers a runtime deprecation, unlike the @deprecated annotation; use \"phpstan/phpstan-deprecation-rules\" to report the annotation instead","errorType":"exception","errorClass":"ShouldNotHappenException","httpStatus":null,"severity":"error","filePath":"rules/Php85/Rector/Const_/ConstAndTraitDeprecatedAttributeRector.php","lineNumber":44,"sourceCode":" */\nconst SomeConstant = 'irrelevant';\nCODE_SAMPLE\n, <<<'CODE_SAMPLE'\n#[\\Deprecated(message: 'Use SomeOtherConstant instead', since: '1.0.0')]\nconst SomeConstant = 'irrelevant';\nCODE_SAMPLE\n)]);\n    }\n    public function getNodeTypes(): array\n    {\n        return [Const_::class, Trait_::class];\n    }\n    /**\n     * @param Const_|Trait_ $node\n     */\n    public function refactor(Node $node): ?Node\n    {\n        throw new ShouldNotHappenException(sprintf('\"%s\" rule is deprecated, as the #[Deprecated] attribute triggers a runtime deprecation, unlike the @deprecated annotation; use \"phpstan/phpstan-deprecation-rules\" to report the annotation instead', self::class));\n    }\n    public function provideMinPhpVersion(): int\n    {\n        return PhpVersion::PHP_85;\n    }\n}\n","sourceCodeStart":26,"sourceCodeEnd":51,"githubUrl":"https://github.com/rectorphp/rector/blob/408fcb0ff1833e3d26cbc9b04c23a77565814a16/rules/Php85/Rector/Const_/ConstAndTraitDeprecatedAttributeRector.php#L26-L51","documentation":"Rector\\Php85\\Rector\\Const_\\ConstAndTraitDeprecatedAttributeRector is deprecated: refactor() throws Rector\\Exception\\ShouldNotHappenException on the first Const_ or Trait_ node. Like its PHP 8.4 sibling (DeprecatedAnnotationToDeprecatedAttributeRector), it converted the passive @deprecated annotation into #[Deprecated], but the attribute emits a real runtime deprecation notice - an unintended behavior change. Use phpstan/phpstan-deprecation-rules to report the annotation during static analysis instead.","triggerScenarios":"The rule is still present in a PHP 8.5 upgrade config and rector visits any const statement (class const or top-level const) or trait declaration; refactor() throws on the first match.","commonSituations":"Running a copied withPhp85() era config after the rule was gutted; CI failing immediately after `composer update rector/rector`; enabling every Php85 rule wholesale to 'modernize' a codebase.","solutions":["Remove ConstAndTraitDeprecatedAttributeRector from rector.php.","Keep @deprecated annotations on constants/traits and report their usage via phpstan/phpstan-deprecation-rules.","Add #[Deprecated] manually only where a runtime notice is deliberately desired."],"exampleFix":"// before (rector.php)\n->withRules([ConstAndTraitDeprecatedAttributeRector::class])\n\n// after (rector.php) - removed; keep annotations, check statically\n// composer require --dev phpstan/phpstan-deprecation-rules","handlingStrategy":"validation","validationCode":"use Rector\\Php85\\Rector\\Const_\\ConstAndTraitDeprecatedAttributeRector;\n\n$rules = [/* your list */ ConstAndTraitDeprecatedAttributeRector::class];\nif (in_array(ConstAndTraitDeprecatedAttributeRector::class, $rules, true)) {\n    throw new InvalidArgumentException('Rule deprecated; use phpstan/phpstan-deprecation-rules for @deprecated reporting');\n}","typeGuard":null,"tryCatchPattern":"try {\n    exit($rectorApplication->run());\n} catch (\\Rector\\Exception\\ShouldNotHappenException $e) {\n    if (str_contains($e->getMessage(), 'ConstAndTraitDeprecatedAttributeRector')) {\n        fwrite(STDERR, 'Remove the rule; #[Deprecated] on consts/traits fires runtime notices - report statically instead.' . PHP_EOL);\n        exit(1);\n    }\n    throw $e;\n}","preventionTips":["When adopting a new PHP level set, diff your explicit rule list against the set's current contents rather than copying old lists forward.","Prefer annotation-based deprecation plus PHPStan reporting unless a runtime notice is explicitly required.","Add a CI grep step that fails on known-deprecated rule class names appearing in rector.php."],"tags":["rector","php","deprecation","attributes","phpstan","php85"],"backgroundTag":"deprecated-api-invoked","analyzedSha":"408fcb0ff1833e3d26cbc9b04c23a77565814a16","analyzedAt":"2026-08-21T05:11:02.643Z","schemaVersion":2},"datasetVersion":"2026-08-21T11:28:35.574Z"}