I saw the plugin "WooCommerce" from WordPress is using the OR operator ( || ) to execute the exit command, below is the code:
defined( 'ABSPATH' ) || exit;
I understand that PHP is "lazy/short-circuit" and will not reach exit if the former is true. But I thought the boolean would always return a boolean value instead of being capable of executing a PHP command like exit? ( refer to the first user contributed note: https://www.php.net/manual/en/language.operators.logical.php )
I mean a||b both "a" and "b" are intended to be something to be tested, and not running a command like a|| // Do something?
Instead the below code is correct and understandable
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
a || bmeans first evaluateaand convert it to a boolean. Then, if the result is nottrue, evaluateb. In this case, evaluatingbmeans "calling"exit, which doesn't return anything.a || bis different froma && bexitis a language construct and not a direct function), that code is effectively the same as these which are also valid