Possible Duplicate: What are the PHP operators “?” and “:” called and what do they do?
<?PHP
require __DIR__.'/c.php';
if (!is_callable($c = @$_GET['c'] ?: function() { echo 'Woah!'; }))
throw new Exception('Error');
$c();
?>
Twitto 使用了 PHP 5.3 之后的几个新功能:
- DIR 常量
- ?: 运算符
- 匿名函数
在 PHP 5.3 中,数字 2 对 ?: 有什么作用?
另外,匿名函数是什么意思?那不是早就存在了吗?
最佳答案
?:
是条件运算符的一种形式,以前只能作为:
expr ? val_if_true : val_if_false
在 5.3 中可以省略中间部分,例如expr ?: val_if_false
相当于:
expr ? expr : val_if_false
来自manual :
Since PHP 5.3, it is possible to leave out the middle part of the conditional operator. Expression
expr1 ?: expr3
returnsexpr1
ifexpr1
evaluates toTRUE
, andexpr3
otherwise.
关于php - 什么是 ? : in PHP 5. 3?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2153180/