-
-
Notifications
You must be signed in to change notification settings - Fork 887
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
Weird error on unset of array #3391
Comments
This is happening because you're getting a union type See: https://phpstan.org/writing-php-code/narrowing-types I agree something should be done about this bug but you need to fix your code anyway :) Otherwise this issue would be reported on level 7: https://phpstan.org/r/f3e6a76b-5f55-4940-89fb-f7f0c4a2e4e7 |
Thanks for the response 😄Agreed, the code isn't the best and needs fixing regardless really. What I find most odd about this bug is that it only shows after altering the array the second time: https://phpstan.org/r/4b79df96-40b4-4720-b270-ac98455f80b3 |
This is what's happening (PHPStan internals): https://phpstan.org/r/e1bdb0e3-c668-418a-9827-37f855cd8302 |
@jackbentley After the latest commit in dev-master, PHPStan now reports different result with your code snippet: @@ @@
-22: Cannot unset offset 'id' on array('bar' => 'b').
+22: Cannot unset offset 'id' on array{bar: 'b'}. Full report
|
@ondrejmirtes After the latest commit in dev-master, PHPStan now reports different result with your code snippet: @@ @@
22: Cannot access offset 'foo' on array|bool|float|int|string.
-25: Cannot unset offset 'id' on array('bar' => 'b').
+25: Cannot unset offset 'id' on array{bar: 'b'}. Full report
|
@ondrejmirtes After the latest commit in dev-master, PHPStan now reports different result with your code snippet: @@ @@
-22: Cannot unset offset 'id' on array('bar' => 'b').
+22: Cannot unset offset 'id' on array{bar: 'b'}. Full report
|
@jackbentley After the latest push in 1.8.x, PHPStan now reports different result with your code snippet: @@ @@
-22: Cannot unset offset 'id' on array('bar' => 'b').
+No errors |
@ondrejmirtes After the latest push in 1.8.x, PHPStan now reports different result with your code snippet: @@ @@
-22: Cannot access offset 'foo' on array|bool|float|int|string.
-25: Cannot unset offset 'id' on array('bar' => 'b').
+22: Cannot access offset 'foo' on array|bool|float|int|string. Full report
|
@ondrejmirtes After the latest push in 1.8.x, PHPStan now reports different result with your code snippet: @@ @@
-22: Cannot unset offset 'id' on array('bar' => 'b').
+No errors |
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. |
Bug report
I'm utilising the Symfony Normalizer in my project. I've only got PHPStan on level 2 but this error occurs when trying to unset a value returned in the serializer.
Code snippet that reproduces the problem
Expected output
No errors.
Examples
This shows the error:
https://phpstan.org/r/d3f05294-9abc-4f48-ad77-c71d371b4cfd
However, when removing either of lines 8/20/21 the error goes away...
https://phpstan.org/r/fba7b0b0-735f-4ba5-8fc4-b33a94dcff04
or... https://phpstan.org/r/4b79df96-40b4-4720-b270-ac98455f80b3
The text was updated successfully, but these errors were encountered: