2

I realise that the answer to this question is probably going to be simply obvious, but I am stumped.

I've created a class that uses Jeremy Kendall's Password Validator (https://github.com/jeremykendall/password-validator) called Hash. However, when the class gets called I get:

Parse error: syntax error, unexpected '}' in /home/james/Projects/REC/htdocs/classes/Hash.class.php on line 24.

The code in Hash.class.php that it is having issues with is:

private $validationCallback;

public function __construct(){
    $this->validationCallback = function($credential, $passwordHash){
        if (has('md5', $credential) === $passwordHash) {
            return true;
        }
        return false;
    }
}

Line 24 is the final '}'. Any help would be greatly appreciated.

Thanks.

1
  • MD5? Lordie, do they still use that in the 21st century? Commented Apr 25, 2014 at 11:58

2 Answers 2

6

This should be:

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
}

Please see PHP's Anonymous Function documentation:

Closures can also be used as the values of variables; PHP automatically converts such expressions into instances of the Closure internal class. Assigning a closure to a variable uses the same syntax as any other assignment, including the trailing semicolon:

Sign up to request clarification or add additional context in comments.

Comments

3

Anonymous functions need a semicolon at the end. Try this:

private $validationCallback;

public function __construct(){
$this->validationCallback = function($credential, $passwordHash)
{
if (has('md5', $credential) === $passwordHash) {
    return true;
}
return false;

};
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.