I am trying to define a constant inside of a function but I keep getting a syntax error. If I define this at the top of the file outside of the function and class it works define('SALT_LENGTH', 9); As soon as I put this inside the class or function I get syntax error I have also tried const SALT_LENGTH = 9; but it is the same issue. I have been searching around for answers but I am not finding anything.
class userFunctions{
//Generate an encrypted password method
public function generateHash($password, $salt = null)
{
if ($salt === null) {
$salt = substr(md5(uniqid(rand(), true)), 0, SALT_LENGTH);
} else {
$salt = substr($salt, 0, SALT_LENGTH);
}
return $salt . sha1($salt . $password);
}
//End of generate encrypted password method
}