I created this class
Youre getting that error because the visibility of the method must be the same or less restrictive than that of it its definition on a parent class. In this case you have addErrors
as public
on your abstract class and are attempting to make it protected
on a child class.
Since PHP 7.2.0 there was a bug #61970 fixed (Restraining __construct()
access level in subclass gives a fatal error).
Bump your PHP version to 7.2 and you could make it private
or protected
.
You've specify the protected
access to the protected function _addErrors(array $errors)
method of Form_Element_Validators
class. So change it to public.
Edit:
Have you noticed? The sub class method (overridden method) is defined with Type Hinting. Please keep the same parameter type for both; super-class and sub-class method.
abstract class Validator{
public $_errors = array();
abstract public function isValid($input);
public function _addErrors(array $message){
$this->_errors = $message;
}
....
It also happens when you are trying to do something with specific guard. You can add
protected $guard = "guard_name";
Add above line in your model. that will solve the problem.
As others have mentioned, you can't make a sub class method more restrictive than the parent; this is because sub classes are supposed to be a valid replacement for their parent class.
In your particular case, I would change the visibility of all methods and properties that start with an underscore to protected
.