我需要编辑一个函数,但我无法弄清楚是什么?和返回声明中的:false mean.我认为:是OR还是?我不知道.
public function hasPermission($name)
{
return $this->getVjGuardADUser() ? $this->getVjGuardADUser()->hasPermission($name) : false;
}
有谁能为我解决这个问题?
它是PHP的三元运算符.它就像是if/else表达式的简写.
您的扩展代码可能如下所示:
public function hasPermission($name)
{
if ($this->getVjGuardADUser()) {
return $this->getVjGuardADUser()->hasPermission($name)
} else {
return false;
}
}
Run Code Online (Sandbox Code Playgroud)
一些来自php.net的示例代码:
// Example usage for: Ternary Operator
$action = (empty($_POST['action'])) ? 'default' : $_POST['action'];
// The above is identical to this if/else statement
if (empty($_POST['action'])) {
$action = 'default';
} else {
$action = $_POST['action'];
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
102 次 |
| 最近记录: |