Skip to content

Array keys using single quotes are narrowed differently than the same array key using double quotes #15060

Description

@PatrickRose

Bug report

I've just run pint against our repository and was surprised by our PHPStan errors increasing.

This mainly turned out to be because we had a baseline for this pattern that existed in the codebase

if (isset($searchParams['key']) && $searchParams['key'] && is_array($searchParams['key'])) {
    if (count($searchParams['key']) > 0) {
        // do query things here
    }
}

PHPStan correctly infers that $searchParams['key'] must be a non-empty array because of the $searchParams['key'] in the if statement.

However, our error count raised because pint rationalised everything to using single quotes and it turns out that using single and double quotes treats the array keys differently. See the attached code snippet

Code snippet that reproduces the problem

https://phpstan.org/r/62bbf8b9-1d65-46d9-8211-7e3f132d2e86

Expected output

PHPStan should have errored on both single and double

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

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions