Skip to content

Null coalesce non-null result implies the caller not to be null - not reflected in consequent conditions #6120

Closed

Description

@janedbal

Feature request

See snippet: https://phpstan.org/r/bb7805f4-89bf-42e7-825b-d4984041c656, it would be nice if phpstan would understand this correlation.

Activity

  1. added this to the Dependent types milestone on Dec 1, 2021
  2. neclimdul commented on Oct 31, 2022

    @neclimdul

    Think I ran into the same issue with a property. Ran into this implementing the PSR-7 message interface which will close/detach the internal resource leading to some weird object states where the internal resource is no longer set.

    Here's a bit of a contrived example demonstrating it using a generator.
    https://phpstan.org/r/20e1698e-7e49-4793-a542-1640e03e7c6f

  3. added a commit that references this issue on Feb 16, 2026
  4. added a commit that references this issue on Feb 18, 2026
  5. phpstan-bot commented on Feb 18, 2026

    @phpstan-bot
    Contributor

    @neclimdul After the latest push in 2.2.x, PHPStan now reports different result with your code snippet:

    @@ @@
    -16: Cannot call method next() on Generator<int, string, mixed, mixed>|null.
    +No errors
  6. phpstan-bot commented on Feb 19, 2026

    @phpstan-bot
    Contributor

    Closed via merging phpstan/phpstan-src#4995

  7. github-actions commented on Mar 23, 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 Mar 23, 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

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions