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;
}