Where else but in php, the expression 'a' == 0 evaluates to true?

Where else but in php, the expression 'a' == 0 evaluates to true?
July 2nd 19 at 17:22
2 answers
July 2nd 19 at 17:24
Solution
It is possible that anywhere. If you are implying that it is a perversion, and not quite the behavior that is expected - I agree with you, but if you are learning the language with non-strict typing, automatic type coercion and other 'features', you just need to understand exactly how it works. Specifically in PHP and javascript, the operator === for exact comparisons. Well, in the end, in languages with strict typification compare int and string is weird. So write code with the idea that you need to compare 'a' == 'b' or 1==2 and such problems will never face.
July 2nd 19 at 17:26
In C and C++ might well be true and may not give. There is undefined behavior.
Why is it UB? Explain plz. For me everything is clear: the char 'a' is compared with the int'om 0 -- in this case, char depromoted to INTA and run a comparison of two intov. In fact, to perform a comparison of the ASCII-code of character 'a' (97) with a value of 0: 97 != 0, the test will return false. - elnora_Murr commented on July 2nd 19 at 17:29
: what standard do you equate 'a' to 97? - otho.Mraz23 commented on July 2nd 19 at 17:32
ASCII-table. In practice 'a' is 97 on any modern system, except perhaps the most exotic. Even if the C++ standard compliance strict character codes ASCII table and does not require.
Even if suddenly where-that will meet the 'a' != 97, then certainly 'a' is not null -- the null code will be for the NUL character. - elnora_Murr commented on July 2nd 19 at 17:35
: where it is written in the standard? Why can't there be some sort of exotic encoding, where a null symbol is 255 and null - a? - otho.Mraz23 commented on July 2nd 19 at 17:38

Find more questions by tags Programming languagesPHP