Skip to content

Remove PHP version contraint from the #[\NoDiscard] attribute rule #14586

Closed

Description

@claudepache

Feature request

The reasoning is the same as for the #[\Override] attribute.

TL;DR: (a) the explicit use of #[\NoDiscard] is already an opt-in by itself, and (b) I am eager to benefit from the attribute via static analysis even though I am still running on 8.4.

#[\NoDiscard]
function f(): int {
	return random_int(0, 4);
}

f(); // PHPStan should warn, regardless of PHP version

Of course, the (void) cast remains available in PHP 8.5+ only.

Code snippet that illustrates the issue

https://phpstan.org/r/bdb96b34-86b0-45a2-9723-98612f87da6f

Expected output

The error on line 8 should not be restricted to PHP 8.5+.

Did PHPStan help you today? Did it make you happy in any way?

No response

Activity

  1. staabm commented on May 7, 2026

    @staabm
    Contributor

    is this the idea as suggested here #13009 ? ondrej had a opinion about it back then

  2. VincentLanglet commented on Sep 13, 2026

    @VincentLanglet
    Contributor

    Would you be interested on doing the PR @claudepache I think it's an easy one and we will ping ondrej on it ;)

  3. staabm commented on Sep 13, 2026

    @staabm
    Contributor

    Ondrej had a strong opinion on it. Not sure we could accept it

    See #13009 (comment)

  4. VincentLanglet commented on Sep 13, 2026

    @VincentLanglet
    Contributor

    Ondrej had a strong opinion on it. Not sure we could accept it

    I saw ondrej answer but I feel like the argument is correct here:

    • noDiscard check is opt-in like the override one.
    • override removes the php version constraint
  5. claudepache commented on Sep 14, 2026

    @claudepache
    Author

    Would you be interested on doing the PR @claudepache I think it's an easy one and we will ping ondrej on it ;)

    Done: phpstan/phpstan-src#6444

  6. phpstan-bot commented on Sep 14, 2026

    @phpstan-bot
    Contributor

    Closed via merging phpstan/phpstan-src#6444

  7. github-actions commented on Oct 16, 2026

    @github-actions

    This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

  8. locked as resolved and limited conversation to collaborators on Oct 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions