-
-
Notifications
You must be signed in to change notification settings - Fork 947
Error when casting values from mixed array to int #4490
Copy link
Copy link
Closed
Description
Good Morning
I do have an array with multiple values that may be an int or string. If try to cast those values to int in a foreach loop, I get the following error: Cannot cast 1|2|3|'test'
So for example the following code:
<?php
declare(strict_types=1);
foreach ([ 1, 2, 3, 'test' ] as $value) {
$value = (int) $value;
}Returns this result.
5 Cannot cast 1|2|3|'test' to int.
Link to reproduce:
https://phpstan.org/r/91468695-25fb-4e96-922d-1db4fd680b40
Expected output
In my opinion this is valid code. Or am I missing something?
I'm on phpstan 0.12.71, level 7 with php 8.0.1
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels