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

Cannot assign new offset to something that is clearly an array #8015

Closed
derrabus opened this issue Sep 15, 2022 · 3 comments · Fixed by phpstan/phpstan-src#1732
Closed

Cannot assign new offset to something that is clearly an array #8015

derrabus opened this issue Sep 15, 2022 · 3 comments · Fixed by phpstan/phpstan-src#1732
Labels
Milestone

Comments

@derrabus
Copy link

Bug report

I'm operating on an array with dynamic keys. When trying to add an item to a nested array right after initializing it, I get an error, telling me that I cannot assign a new offset to that array.

Code snippet that reproduces the problem

https://phpstan.org/r/7989deba-bb1e-4ad0-b070-c6de9bc2e4f3

The crucial part is this piece:

$config['things'] = [];
foreach ($item as $thing) {
    $config['things'][] = (string) $thing;
}

PHPStan complains about the assignment inside the foreach loop. But at this point, $config['things'] is guaranteed to be an array.

Expected output

No error.

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

Only today? PHPStan improves my live as a developer every day!

@ondrejmirtes
Copy link
Member

Fixed by phpstan/phpstan-src#1732

@derrabus
Copy link
Author

derrabus commented Oct 5, 2022

Awesome, thank you very much @herndlm!

@github-actions
Copy link

github-actions bot commented Nov 6, 2022

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

Successfully merging a pull request may close this issue.

2 participants