I got an 'interesting' TypeError that (should) not have happened ? #16835
rayanlevert
started this conversation in
General
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hello,
The message of the Fatal Error is actually pretty disturbing, makes me wonder if is this not an internal PHP bug ? (would be crazy right)
So, here's the model, (removing all the interesting methods/properties)
And then what I'm trying to achieve, is passing an array with
propertyin it, of a integer value, classic.But the thing is, I'm calling
array_walkto the array before.And I'm initializing the model, and I get the Fatal Error (prepare yourselves)
Fatal error: Uncaught TypeError: Cannot assign int to property Model::$property of type int in /app/src/Tasks/MainTask.php on line 39
Cannot assign int to property of type int, that's the weird part, right ?
As soon as I traverse the array by reference, I got the error, another way for example
I've tried with string, or float, same error.
The error is linked to the typed property, if I remove the int (
public $property = 0) - it works.I've tried with the mixed type, same error - Cannot assign int to property App\Models\Test::$property of type mixed (which should never happen, mixed can assign every type).
Well, this is not a bug or something, we can just not use reference nor use array_walk, but I couldn't reproduce it anywhere else than the model assign.
Have fun coding - thanks for reading.
Beta Was this translation helpful? Give feedback.
All reactions