I am currently studying ZEND framework and came across this in index.php:
// Define path to application directory
defined('APPLICATION_PATH')
|| define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../application'));
Is this the same as this?
if(!defined('APPLICATION_PATH')){
define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../application'));
}
I have never came across this type of shorthand syntax before.
Basic PHP Syntax A PHP script can be placed anywhere in the document. The default file extension for PHP files is " .php ". A PHP file normally contains HTML tags, and some PHP scripting code.
PHP is whitespace insensitive PHP whitespace insensitive means that it almost never matters how many whitespace characters you have in a row. one whitespace character is the same as many such characters.
||
is a short-circuit operator which means that the second operand, in this case define(...)
is only evaluated in case the first operand evaluates to false. Because operands to shirt-circuit operators may actually have side effects as is your case, short-circuiting may substitute an if
statement.
Check this article: http://en.wikipedia.org/wiki/Short-circuit_evaluation
Functionally, yes, it is the same. The defined
function returns a boolean, so it uses short-circuit evaluation to mean "either this is defined, OR execute this definition."
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With