Skip to content

False positive with null coalescing operator #6026

@mind-bending-forks

Description

@mind-bending-forks

Bug report

According to the docs, $a ?? $b is functionally equivalent to isset($a) ? $a : $b. However, PHPstan seems to treat them differently.

Code snippet that reproduces the problem

See lines 14 (null coalescing) and 15 (isset) of the following:

https://phpstan.org/r/ff7c5d16-abb6-4445-b950-1799077559ce

An error is produced for line 14 (null coalescing):

Access to an undefined property object::$datalen

but not for line 15 (isset).

Expected output

No error should be produced for line 14.

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

Yes.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions