我在 Zend Framework 项目的默认 index.php 文件中遇到了这个有趣的行:
defined('APPLICATION_PATH')
|| define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../application'));
好像在说“如果没有定义APPLICATION_PATH,那就继续定义吧……”
我不知道 PHP 中有这种控制结构。这几乎就像一个“隐含的如果”或“如果/其他”。谁能帮我解决这个问题?
最佳答案
它不是一个控制结构 - 它就是 ||
的工作方式。如果第一个操作数被评估为 true
- 那么第二个操作数根本不会被评估。
http://php.net/manual/en/language.operators.logical.php --- 查看示例的前 4 行。
// --------------------
// foo() will never get called as those operators are short-circuit
$a = (false && foo());
$b = (true || foo());
$c = (false and foo());
$d = (true or foo());
关于php - 有趣的 PHP 语法 : an 'implied if' ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4881935/