Skip to content

positive is_string on an array element with null coalesce operator should mark the element as string #7244

@oliverklee

Description

@oliverklee

Bug report

PHPStan correctly recognizes that an array element is a string with this code:

\is_string($arguments['format']) ? $arguments['format'] : 'Y-m-d';

When I add a null coalesce operator to avoid invalid array accesses, this does not work anymore:

\is_string($arguments['format'] ?? null) ? $arguments['format'] : 'Y-m-d';

Code snippet that reproduces the problem

https://phpstan.org/r/0ee835f9-8142-4b60-9ce1-8a8006c96a3c

Expected output

No error.

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

❤️

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