class - PHP Fatal error: Call to protected method FormValidator::setError() from context '' -


consider poor class:

abstract class formvalidator {     private $error_objects = array();      protected function seterror($entry_name,$err_msg)     {         $this->error_objects[] =              new formvalidatorerrorobject($entry_name,$err_msg);     }      protected function seterrorcurry($entry_name)     {         $_this = $this;         return function($err_msg) use($entry_name,$_this)         {             return $_this->seterror($entry_name,$err_msg);         };     }      public function counterrors()     {         return count($this->error_objects);     }      public function geterror($index)     {         return $this->error_objects[$index];     }      public function getallerrors()     {         return $this->error_objects;     }      abstract function validate(); } 

i use in implementing class this:

$seterror = $this->seterrorcurry('u_email');     if(empty($uemail))     {         $seterror(uregform_errmsg_email_null);     }      if(!filter_var($uemail,filter_validate_email))     {         $seterror(uregform_errmsg_email_invalid);     } 

and results in following error:

fatal error: call protected method formvalidator::seterror() context '' ... 

question: there way make closure "inherit" class context?

apparently not natively. this manual note suggests rather cumbersome way of using reflection , wrapper class give closures private/protected access functionality though.


Comments

Popular posts from this blog

java - SNMP4J General Variable Binding Error -

windows - Python Service Installation - "Could not find PythonClass entry" -

Determine if a XmlNode is empty or null in C#? -