Skip to content

Conversation

@jrfnl
Copy link
Member

@jrfnl jrfnl commented Nov 18, 2025

Description

PHP 8.5 | Tokenizer/PHP: polyfill the (void) cast

As part of the RFC for the #[NoDiscard] attribute, a new typecast (void) has been introduced.

This commit polyfills this new token for PHP < 8.5.

Includes tests covering the complete set of type casts, even though the PHPCS Tokenizer only handles the (void) cast.
Reason being, that PHP has deprecated and removed some casts, like (unset), and their token constants may be removed from PHP Core at some point in the future. These tests should serve as a warning system for that eventuality.

Ref: https://wiki.php.net/rfc/marking_return_value_as_important#void_cast_to_suppress_the_warning

Various sniffs: add tests with PHP 8.5 (void) cast

Suggested changelog entry

Added

  • Tokenizer support for the new PHP 8.5 (void) cast.
    • The T_VOID_CAST token has been added to the Tokens::CAST_TOKENS array.

Related issues/external references

Related to #1306

As part of the RFC for the `#[NoDiscard]` attribute, a new typecast `(void)` has been introduced.

This commit polyfills this new token for PHP < 8.5.

Includes tests covering the complete set of type casts, even though the PHPCS Tokenizer only handles the `(void)` cast.
Reason being, that PHP has deprecated and removed some casts, like `(unset)`, and their token constants may be removed from PHP Core at some point in the future. These tests should serve as a warning system for that eventuality.

Ref: https://wiki.php.net/rfc/marking_return_value_as_important#void_cast_to_suppress_the_warning
@jrfnl jrfnl force-pushed the php-8.5/1306-tokenizer-php-polyfill-void-cast branch from 392784d to be46b97 Compare November 18, 2025 05:47
@jrfnl
Copy link
Member Author

jrfnl commented Nov 18, 2025

Rebased without changes to get a passing build after #1326

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