2 ms·
You can chain !, so "true == !! true" is true.
by DougBTX 18y ago
You can chain !, so "true == !! true" is true.
- randallsquared 18y agoYou can, but I can't think of any reason to do so, which is why I mentioned it.
- qqq 18y agogenerated code to convert stuff to explicit true/false
- randallsquared 18y ago> generated code Not a problem: either the PHP generated is only safe for a particular version, or they can add parenthesis to distinguish the cases. > to convert stuff to explicit true/false I suppose. That would seem like a surprising use to me, and would merit an explanatory comment, but given that, it might be better to just explicitly cast ("(bool)$name"), which saves the comment, and only adds four characters over "!!$name".
- qqq 18y agoEvery syntax quirk that requires the code generator to do something (e.g. add more parentheses) makes code generation harder.
- randallsquared 18y agoI would naively expect every single expression to be surrounded by parenthesis by default, implemented in the lowest level writeExpression() function or whatever. But I've never written a translator, so...
- DougBTX 18y agoWhich of these would be the same? !(!(true)) ! ! true !!true Having !! not be the same as ! ! would probably be the first case in PHP of significant whitespace.
- randallsquared 18y agoI would assume that the first would be different than the second two, in the case that !! was some other operator. It's not clear to me whether other cases in which there are double-character operators tolerate having whitespace between them. Is "$name++" the same as "$name+ +", or is the latter an error, or neither? I can't be bothered to check right now. :)