Skip to content

Conversation

@jrfnl
Copy link
Member

@jrfnl jrfnl commented Dec 26, 2022

PHP 8.0 | NewTypedProperties: examine properties declared in the constructor

Typed properties declared via a class constructor should also be examined by the NewTypedProperties sniff as the allowed types for properties are different than those for parameters.

Includes:

  • Adding T_FUNCTION to the tokens to be examined.
  • Splitting the "type checking" logic off into its own method to allow for multiple properties declared in a constructor.

Includes unit tests.

Ref: https://wiki.php.net/rfc/constructor_promotion

PHP 8.0 | NewParamTypeDeclarations: ignore promoted properties

Properties declared via a class constructor follow the property type rules, not the parameter type rules, so ignore them for this sniff. These will be examined in the NewTypedProperties sniff instead.

Includes unit tests.

Related to #809

…tructor

Typed properties declared via a class constructor should also be examined by the `NewTypedProperties` sniff as the allowed types for properties are different than those for parameters.

Includes:
* Adding `T_FUNCTION` to the tokens to be examined.
* Splitting the "type checking" logic off into its own method to allow for multiple properties declared in a constructor.

Includes unit tests.

Ref: https://wiki.php.net/rfc/constructor_promotion
Properties declared via a class constructor follow the property type rules, not the parameter type rules, so ignore them for this sniff. These will be examined in the `NewTypedProperties` sniff instead.

Includes unit tests.
@wimg wimg merged commit 344191d into develop Dec 30, 2022
@wimg wimg deleted the php-8.0/newtypedproperties-newparamtype-support-constructor-property-promotion branch December 30, 2022 15:38
@jrfnl jrfnl added the PHP: 8.0 label Nov 4, 2025
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.

3 participants