难以理解 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;

它是一个条件语句吗?或者类似三元运算符的东西? 谢谢


慕少森
浏览 63回答 1
1回答

翻翻过去那场雪

他们试图通过使用处理此类逻辑运算符时发生的短路来变得聪明。这就是他们正在做的事情:if ((static::$info['syntax'] === null) || $force) {    static::$info['syntax'] = $syntax;}如果您想了解此短路如何与 &&/and 运算符配合使用:$a = 'something';false && $a = 'else';echo $a;// output: something由于第一部分是 false,因此它甚至不会在另一端运行该语句,因为此逻辑运算的计算结果已为 false。
打开App,查看更多内容
随时随地看视频慕课网APP