You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Both eq_strings and eq_byte_arrays should evaluate to false, but they evaluate to true in the generated PHP parser. The reason is written in PHP documentation:
If both operands are numeric strings, or one operand is a number and the other one is a numeric string, then the comparison is done numerically. These rules also apply to the switch statement. The type conversion does not take place when the comparison is === or !== as this involves comparing the type as well as the value.
The solution would be to use the strict equality operator === instead, which does not perform type juggling. The catch I can foresee is that simply switching entirely to === would break expressions like 2.0 == 2 (which the KS expression language apparently allows), since float and int are different types (var_dump(2.0 === 2) is bool(false)).
Reproducible example:
As of kaitai-io/kaitai_struct_compiler@12dbc32, it is translated to PHP as follows:
Both
eq_strings
andeq_byte_arrays
should evaluate tofalse
, but they evaluate totrue
in the generated PHP parser. The reason is written in PHP documentation:The solution would be to use the strict equality operator
===
instead, which does not perform type juggling. The catch I can foresee is that simply switching entirely to===
would break expressions like2.0 == 2
(which the KS expression language apparently allows), sincefloat
andint
are different types (var_dump(2.0 === 2)
isbool(false)
).We should also pay attention to this part:
This means that we run into the same problem with type switching, because this .ksy snippet...
... is translated into a
switch
statement:The text was updated successfully, but these errors were encountered: