On 10 July 2018 at 04:02, Ryan <iggyv...@gmail.com> wrote:

>
> defined("SOME_CONSTANT") or die("SOME_CONSTANT was not defined");
>
> However, this behaviour has nothing to do with the difference of precedence
> - rather this is due to short circuiting.
>


As your own next example demonstrates, it does rely on the difference in
precedence, because without it, you could only use this idiom after
carefully checking that the left-hand side would be evaluated in one go,
and probably using an extra set of parentheses.


> ($gdImage = @imagecreatetruecolor(120, 20)) || die('Cannot Initialize new
GD image stream');

This is less readable both because of the extra parentheses, and because
the || operator is not as easily read as the English word "or".

While I've not seen it used much in PHP code, the "do this or die" idiom is
common in Perl (which also has post-fix "if" and "unless" modifiers, so
those are a different feature again).

IF there is sufficient harm in having the extra operators, I would say
removal is the only option - making them behave as aliases for || etc would
just lead to even more confusion when they *don't* work the same way as in
Perl, and in earlier versions of PHP. I'm not 100% convinced by the harm,
though.


Finally, a note on the "xor" operator - your draft says that this is
equivalent to "!=", but that is not the case, because both can operate on
non-boolean values. Consider "1 != 2" (true) vs "1 xor 2" (false). I don't
think I've ever had a use for logical xor in PHP code, but there isn't
anything to confuse it with, so no reason to remove it.

Regards,
-- 
Rowan Collins
[IMSoP]

Reply via email to