-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Closed
Description
Currently, there's the following list of edge cases, on https://twig.symfony.com/doc/2.x/tags/if.html
This is innacurate/incomplete, as these edge cases have edge cases.
These are my findings:
- empty string:
false - numeric zero:
false - whitespace-only string:
false?
Runningecho !!' ';shows 1
Runningecho ' ' == 0;shows 1
Runningecho ' ' == '0';doesn't display anything
The whitespace-only string (or any string) will be casted to a number when compared for equality with a number. Otherwise, everything is casted to a string. - empty array:
false
Everything is casted to an array when comparing to an empty array, except boolean values. In that case, the empty array is casted to the boolean value (false) - null:
false
Null is a special value. Null will cast to a string when comparing with a string, to a number when comparing to a number but won't be cast to an empty array when comparing to an empty array.
My guess is due to the fact that you can writefunction xyz(array $arg = null){ [...] }, to distinguish between an empty array and a function with an optional parameter.
Everything below is correct.
You can see it in action on http://sandbox.onlinephpfunctions.com/code/e4dc15a4f29cd6ef6a7498ad27ac202f5f874612
Should this information be added to the documentation? Is it fine the way it is?
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels
