【发布时间】:2011-01-10 07:47:06
【问题描述】:
可能重复: 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 对 ?: 有什么作用?
另外,匿名函数是什么意思?那不是早就存在了吗?
【问题讨论】:
-
@gordon,我知道这对这些主题意味着什么,我认为这是不同的,因为该网站说它是 5.3 的新功能,而且我从未像“?:”那样看到它们在一起跨度>
-
@Gordon 这些只是较长的形式。 @jasondavis,你有 : 和 ?在问题标题中倒退。
-
啊好吧。 新 是你可以省略中间部分。匿名函数(lambda 和闭包)也是 5.3 的新增功能,尽管您之前可以使用
create_function创建函数。 -
这不是重复的。
标签: php php-5.3 ternary-operator conditional-operator language-construct