Skip to content

Fix dangerous use of value of token constants #840

Merged
GaryJones merged 2 commits intodevelopfrom
feature/fix-problematic-token-comparisons
Jul 17, 2025
Merged

Fix dangerous use of value of token constants #840
GaryJones merged 2 commits intodevelopfrom
feature/fix-problematic-token-comparisons

Conversation

@jrfnl
Copy link
Copy Markdown
Collaborator

@jrfnl jrfnl commented Jul 16, 2025

Fix dangerous use of value of token constants

The value of tokens constants is not guaranteed, so should never be compared against directly.

Either use the token 'code' and compare against the constant (preferred).
Or use the token 'type' and compare against the constant name.
But never compare against the value of the constant.

Comparing against the 'type' should generally only be needed for tokens which may not exist in older PHPCS/PHP versions.

Fix unnecessary comparison against token type

jrfnl added 2 commits July 17, 2025 00:40
The value of tokens constants is not guaranteed, so should never be compared against directly.

Either use the token 'code' and compare against the constant (preferred).
Or use the token 'type' and compare against the constant name.
But **_never_** compare against the value of the constant.

Comparing against the 'type' should generally only be needed for tokens which may not exist in older PHPCS/PHP versions.
@jrfnl jrfnl added this to the 3.1.0 milestone Jul 16, 2025
@jrfnl jrfnl requested a review from a team as a code owner July 16, 2025 22:41
@jrfnl jrfnl changed the title Fix dangerous use of contents of constants Fix dangerous use of value of token constants Jul 16, 2025
@GaryJones GaryJones merged commit fe2eaf3 into develop Jul 17, 2025
42 checks passed
@GaryJones GaryJones deleted the feature/fix-problematic-token-comparisons branch July 17, 2025 06:36
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.

2 participants