假設我們在一個類中有這個方法: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;它是一個條件語句嗎?或者類似三元運算符的東西? 謝謝
1 回答

翻翻過去那場雪
TA貢獻2065條經驗 獲得超14個贊
他們試圖通過使用處理此類邏輯運算符時發生的短路來變得聰明。這就是他們正在做的事情:
if ((static::$info['syntax'] === null) || $force) {
static::$info['syntax'] = $syntax;
}
如果您想了解此短路如何與 &&/and 運算符配合使用:
$a = 'something';
false && $a = 'else';
echo $a;
// output: something
由于第一部分是 false,因此它甚至不會在另一端運行該語句,因為此邏輯運算的計算結果已為 false。
- 1 回答
- 0 關注
- 164 瀏覽
添加回答
舉報
0/150
提交
取消