Skip to content

Remove the PHP version constraint from the #[\NoDiscard] attribute rules. - #6444

Merged
ondrejmirtes merged 1 commit into
phpstan:2.2.xfrom
claudepache:nodiscard
Sep 14, 2026
Merged

ondrejmirtes merged 1 commit into
phpstan:2.2.xfrom
claudepache:nodiscard

Conversation

@claudepache

@claudepache claudepache commented Sep 14, 2026 •

Copy link
Copy Markdown
Contributor

Same reasoning as #4436.

In short: Currently, the rules triggered by the #[NoDiscard] attribute are enabled for PHP 8.5+ only, because the attribute was introduced in 8.5. However, as the rules are already implicitly opt-in by the presence of the attribute, there is no need to add a version constraint.

This PR proposes to remove the PHP version constraint from these rules, so that they can be applied to a codebase which supports versions of PHP older than 8.5 and still benefit from static analysis by PHPStan.

Note that the companion VoidCastRule is not touched: the (void) cast remains only available in PHP 8.5+.

Fixes phpstan/phpstan#14586

@ondrejmirtes ondrejmirtes left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other than the note I'm okay with this 👍

Comment thread src/Php/PhpVersion.php
@ondrejmirtes
ondrejmirtes merged commit 76f47dd into phpstan:2.2.x Sep 14, 2026
853 of 884 checks passed
@ondrejmirtes

Copy link
Copy Markdown
Member

Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants