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

??= operator support (PHP 7.4) #2940

Closed
alexeyshockov opened this issue Mar 8, 2020 · 2 comments
Closed

??= operator support (PHP 7.4) #2940

alexeyshockov opened this issue Mar 8, 2020 · 2 comments
Labels

Comments

@alexeyshockov
Copy link

https://psalm.dev/r/97ea41c274 — an example.

Currently Psalm reports EmptyArrayAccess error in the first part of the code above, while the second part is OK.

Bit they are equivalent, the first one just uses short assignment via ??= operator. So no errors should be reported.

@psalm-github-bot
Copy link

I found these snippets:

https://psalm.dev/r/97ea41c274
<?php

/** @var array<array{parcel_id: string, location_id: string}> */
$matches = [];

$bestMatches = [];
foreach ($matches as $match) {
    $bestMatches[$match['parcel_id']] ??= $match['location_id'];
}

foreach ($matches as $match) {
    $bestMatches[$match['parcel_id']] = $bestMatches[$match['parcel_id']] ?? $match['location_id'];
}
Psalm output (using commit 8926f1d):

ERROR: EmptyArrayAccess - 8:5 - Cannot access value on empty array variable $bestMatches

@muglug muglug added the bug label Mar 9, 2020
@muglug muglug closed this as completed in 04bcc32 Mar 9, 2020
@alexeyshockov
Copy link
Author

Thanks a lot!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants