Access Level to certain class must be public error in PHP Access Level to certain class must be public error in PHP php php

Access Level to certain class must be public error in PHP


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.


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.


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;        }        ....