理解PHP语法的困难

理解PHP语法的困难,php,Php,假设我们在一个类中有这个方法: public static function example($s, $f = false) { (static::$i['s'] === null or $f) and static::$i['s'] = $s; return new static; } 你能告诉我这行代码是什么意思吗 (static::$i['s'] === null or $f) and static::$i['s'] = $s; 它是一个条件语句吗?或者像三元运算符之类

假设我们在一个类中有这个方法:

public static function example($s, $f = false)
{
    (static::$i['s'] === null or $f) and static::$i['s'] = $s;
    return new static;
}
你能告诉我这行代码是什么意思吗

(static::$i['s'] === null or $f) and static::$i['s'] = $s;
它是一个条件语句吗?或者像三元运算符之类的东西?
谢谢

他们试图巧妙地利用在处理这样的逻辑运算符时发生的短路。这就是他们正在做的:

if ((static::$info['syntax'] === null) || $force) {
    static::$info['syntax'] = $syntax;
}
如果您想了解此短路如何与
&&
/
操作员一起工作:

$a = 'something';
false && $a = 'else';
echo $a;
// output: something

由于第一部分是
false
,它甚至从未在另一端运行语句,因为此逻辑操作的计算结果已经是
false

,这只是有人试图变得聪明。。。如果
(…)
中的内容最终为
false
,则
静态::$info['syntax']=$syntax
将不会运行(短路)。。。为了清晰起见,他们最好使用
if
语句