Affected page
All attribute class synopsis pages:
Current issue
All attribute class pages show #[\Attribute] in their classsynopsis (added in #5067). This is the shorthand form, which in PHP compiles to #[\Attribute(Attribute::TARGET_ALL)], meaning the attribute can be applied anywhere.
The actual declarations in the PHP stubs are more restrictive:
| Class |
Stubs |
Attribute |
#[Attribute(Attribute::TARGET_CLASS)] |
AllowDynamicProperties |
#[Attribute(Attribute::TARGET_CLASS)] |
Override |
#[Attribute(Attribute::TARGET_METHOD|Attribute::TARGET_PROPERTY|Attribute::TARGET_CLASS_CONSTANT)] |
SensitiveParameter |
#[Attribute(Attribute::TARGET_PARAMETER)] |
Deprecated |
#[Attribute(Attribute::TARGET_METHOD|Attribute::TARGET_FUNCTION|Attribute::TARGET_CLASS_CONSTANT|Attribute::TARGET_CONSTANT|Attribute::TARGET_CLASS)] |
NoDiscard |
#[Attribute(Attribute::TARGET_METHOD|Attribute::TARGET_FUNCTION)] |
DelayedTargetValidation |
#[Attribute(Attribute::TARGET_ALL)] |
A reader who treats the classsynopsis as valid PHP will conclude that #[Override] can be placed on a class or function, which is wrong.
Suggested improvement
Two options:
- Full form: replace
#[\Attribute] with the accurate target list from the stubs in each classsynopsis. Mirrors the source exactly, but requires updating doc-en each time PHP adds a target (e.g. Override gained TARGET_PROPERTY in PHP 8.5).
- Prose note: keep
#[\Attribute] in the classsynopsis and add a sentence in the description listing the valid targets. Lower maintenance, same accuracy.
Additional context
Related: #3897 (superseded by #5067, which adopted the simplified form without discussion of this tradeoff).
Affected page
All attribute class synopsis pages:
Current issue
All attribute class pages show
#[\Attribute]in their classsynopsis (added in #5067). This is the shorthand form, which in PHP compiles to#[\Attribute(Attribute::TARGET_ALL)], meaning the attribute can be applied anywhere.The actual declarations in the PHP stubs are more restrictive:
Attribute#[Attribute(Attribute::TARGET_CLASS)]AllowDynamicProperties#[Attribute(Attribute::TARGET_CLASS)]Override#[Attribute(Attribute::TARGET_METHOD|Attribute::TARGET_PROPERTY|Attribute::TARGET_CLASS_CONSTANT)]SensitiveParameter#[Attribute(Attribute::TARGET_PARAMETER)]Deprecated#[Attribute(Attribute::TARGET_METHOD|Attribute::TARGET_FUNCTION|Attribute::TARGET_CLASS_CONSTANT|Attribute::TARGET_CONSTANT|Attribute::TARGET_CLASS)]NoDiscard#[Attribute(Attribute::TARGET_METHOD|Attribute::TARGET_FUNCTION)]DelayedTargetValidation#[Attribute(Attribute::TARGET_ALL)]A reader who treats the classsynopsis as valid PHP will conclude that
#[Override]can be placed on a class or function, which is wrong.Suggested improvement
Two options:
#[\Attribute]with the accurate target list from the stubs in each classsynopsis. Mirrors the source exactly, but requires updating doc-en each time PHP adds a target (e.g.OverridegainedTARGET_PROPERTYin PHP 8.5).#[\Attribute]in the classsynopsis and add a sentence in the description listing the valid targets. Lower maintenance, same accuracy.Additional context
Related: #3897 (superseded by #5067, which adopted the simplified form without discussion of this tradeoff).