4 ms·
This is commonly seen in Perl and PHP with stuff like launchMissiles() or die('failure');
by cldr 13y ago
This is commonly seen in Perl and PHP with stuff like
launchMissiles() or die('failure');
- k3n 13y agoUgh, `or` is mostly useless in PHP. That code is identical to: launchMissiles() || die('failure');
- ars 13y agoThat code is the same, but or has a lower priority than ||, so they are not the same is the code before the or is an expression. Also, using or instead or || for these types of things is more readable since it makes your intent of conditional code execution (as opposed to boolean evaluation) clear.
- k3n 13y agoMeh, it's not more unreadable unless you have issues understanding || in the first place... and "or" is still a boolean operation. Considering 99.9% of it's use in PHP is some variant of "connect() or die()", I stand by my statement. Besides, those "connect() or die()" expressions are widely considered bad-practice in the first place.
- eridius 13y agoThe better form of this would be launchMissiles() and die('mutual annihilation");
- pyre 13y agoIt's worth noting that in Perl the 'or' and 'and' operators are not equivalent to || and &&. For instance, they have super low operator precedence: my $variable = 0 or 1; Would result in $variable == 0 because it really looks like this: (my $variable = 0) or 1; I allowed myself to get burned by this once because I didn't read the fine print. ^^;;