我意识到这个问题的答案可能很明显,但我很难过.
我创建了一个使用Jeremy Kendall的密码验证器(https://github.com/jeremykendall/password-validator)的类,名为Hash.然而,当这个类被调用时,我得到:
Parse error: syntax error, unexpected '}' in /home/james/Projects/REC/htdocs/classes/Hash.class.php on line 24.
Run Code Online (Sandbox Code Playgroud)
Hash.class.php中存在问题的代码是:
private $validationCallback;
public function __construct(){
$this->validationCallback = function($credential, $passwordHash){
if (has('md5', $credential) === $passwordHash) {
return true;
}
return false;
}
}
Run Code Online (Sandbox Code Playgroud)
第24行是最后的'}'.任何帮助将不胜感激.
谢谢.
这应该是:
private $validationCallback;
public function __construct(){
$this->validationCallback = function($credential, $passwordHash)
{
if (has('md5', $credential) === $passwordHash) {
return true;
}
return false;
}; // Missing semicolon needs to be here
}
Run Code Online (Sandbox Code Playgroud)
请参阅PHP的匿名函数文档:
闭包也可以用作变量的值; PHP自动将这些表达式转换为Closure内部类的实例.为变量分配闭包使用与任何其他赋值相同的语法,包括尾随分号: