Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR is a follow-up on #8126, where some problems were introduced (see: #8126 (comment)).
Problem
Component properties cast to a union type like
string|int
orstring|float
are broken.For example:
(string) 'foo'
tostring|int $property
is cast to(int) 0
.(string) 'foo'
tostring|float $property
is cast to(float) 0.00
.Cause
Any property (union) casted to
int
orfloat
, was aggressively casted to respectively an integer or float.livewire/src/Mechanisms/HandleComponents/Synthesizers/IntSynth.php
Line 20 in cac2f7b
livewire/src/Mechanisms/HandleComponents/Synthesizers/FloatSynth.php
Line 21 in cac2f7b
Solution
We don't need to aggressively cast the passed values to an integer or float.
Casting is also already partially handled by PHP itself.
After this PR is merged, casting works as follows.
int $property
float $property
int|string $property
(int) 3
, can cause issues(int) 0
, solves issuefloat|string $property
(float) 0.00
, solves issueI've also added some backwards compability for the old situation. The only rare situation in which some problems might occur, is when properties are cast to
int|string
and are set to a string-formatted float. Previously, the string was cast to an integer, now the actual string is set.