我有这个代码:
public function __construct($Directory = null)
{
if ($Directory === null) {
trigger_error("Directory Must Be Set!", E_USER_ERROR);
}
if (isset($Directory)) {
if (!empty(trim($Directory))) { //Error Line
echo "test";
}
}
}
Run Code Online (Sandbox Code Playgroud)
(回声用于我的调试目的.)
我收到了致命的错误:
在写上下文中不能使用函数返回值
根据PHP风暴,这将返回:
变量预期
但直接从这个问题使用代码:
这是正确的语法,因为我过去曾经使用它......但是,在这种情况下,这会引发错误.为什么是这样?
Ken*_*ert 107
从关于empty
函数的PHP文档:
注意:在PHP 5.5之前,empty()仅支持变量; 其他任何东西都会导致解析错误.换句话说,以下内容不起作用:empty(trim($ name)).相反,使用trim($ name)== false.
因此,您必须将该行拆分为以下内容:
$trimDir = trim($Directory);
if(!empty($trimDir))
Run Code Online (Sandbox Code Playgroud)