Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PHPDoc Array shape with nullable key not recognized correctly #10317

Closed
ThomasLandauer opened this issue Dec 16, 2023 · 4 comments
Closed

PHPDoc Array shape with nullable key not recognized correctly #10317

ThomasLandauer opened this issue Dec 16, 2023 · 4 comments
Labels
Milestone

Comments

@ThomasLandauer
Copy link
Contributor

Bug report

With a setup like this:

/**
 * @param array{'foo': string, 'bar'?: string} $array
 */
private function myfunction(array $array): int
{
    $string = $array['bar'] ?? $array['foo'];
    return strlen($string);
}

I'm getting:

Parameter #1 $string of function strlen expects string, mixed given.

But from my understanding, $string will always be a string, cause both array keys (foo and bar) are string (if present at all).

This only happens when checkImplicitMixed is enabled; therefore I can't reproduce it in the playground.

Code snippet that reproduces the problem

No response

Expected output

No error message.

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

Sure! :-)

Copy link

mergeable bot commented Dec 16, 2023

This bug report is missing a link to reproduction at phpstan.org/try.

It will most likely be closed after manual review.

@ondrejmirtes ondrejmirtes added this to the Easy fixes milestone Dec 16, 2023
@ondrejmirtes
Copy link
Member

A code sample showing this problem: https://phpstan.org/r/947ba29d-d0a4-493b-804f-d20f053ab92f

@ThomasLandauer ThomasLandauer changed the title PHPDoc Array shape with nullable key not regocnized correctly PHPDoc Array shape with nullable key not recognized correctly Dec 16, 2023
@ondrejmirtes
Copy link
Member

Fixed: phpstan/phpstan-src#2834

Copy link

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 19, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants