CakePHP - Validation rule has syntax error I can't see -


i'm getting parse error: syntax error, unexpected t_variable, expecting ')' on line commented below. can't life of me figure out why it's throwing error.

public $validate = array(     'password1' => array(         'rule1' => array('rule' => 'alphanumeric', 'message' => 'your password should contain alphanumeric characters.'),         'rule2' => array('rule' => '/\d/', 'message' => 'your password must contain @ least 1 numeric character.'),         'rule3' => array('rule' => '/^(?=.*?[a-z])(?=.*?[a-z])/', 'message' => 'your password must contain @ least 1 uppercase , 1 lowercase letter.'),         'rule4' => array('rule' => array('minlength', 8), 'message' => 'your password must @ least 8 characters long.'),     ),     'password2' => array(         // error on line below         'rule' => array('_passwordsmatch', $this->data['passwordreset']['password2']),         'message' => 'the passwords entered not match.'     ) );  /**  * custom validation method check entered passwords match  *  * @param  string $password1  * @param  string $password2  * @return bool  */ protected function _passwordsmatch($password1, $password2) {     return ($password1 === $password2); } 

as can see i'm trying make custom validation rule check 2 passwords coming user's submitted form. related question wrong way trying pass other field value custom rule?

you not allowed reference $this during initialization syntax of class property. if need that, must move array definition class constructor.

quoting documentation:

[properties] defined using 1 of keywords public, protected, or private, followed normal variable declaration. declaration may include initialization, but initialization must constant value--that is, must able evaluated @ compile time , must not depend on run-time information in order evaluated.

this rule enforced @ compile time, there grammar rules static array() syntax not allow arbitrary expressions. why syntax error: instead of $this, parser expects ) closes array(.


Comments

Popular posts from this blog

c# - How to set Z index when using WPF DrawingContext? -

razor - Is this a bug in WebMatrix PageData? -

visual c++ - Using relative values in array sorting ( asm ) -