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

Optional keys in object shapes do not work with null coalesce #10327

Closed
leongersen opened this issue Dec 20, 2023 · 3 comments
Closed

Optional keys in object shapes do not work with null coalesce #10327

leongersen opened this issue Dec 20, 2023 · 3 comments

Comments

@leongersen
Copy link
Contributor

Bug report

Optional keys on objects can be coalesced, but in PHPStan they result in the error type.

This works:

class Test {}

$a = new \stdClass();
$b = new Test();

var_dump($a->optional ?? null, $b->optional ?? null);

Accessing $b->optional without coalesce results in Warning: Undefined property.

Code snippet that reproduces the problem

https://phpstan.org/r/1f24e6ab-289c-45ad-861c-1f7455f55723

Expected output

Both types should be int|null

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

It does! I get excited every time a new PhpStan version is released!

@leongersen
Copy link
Contributor Author

Potentially related to/fixed by #2834

@ondrejmirtes
Copy link
Member

Fixed: phpstan/phpstan-src@d801919

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 22, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants