There is a certain class. There are methods in it. I want to write an error collector, and then output its result to a function from outside the class, how to do it?

Tried like this:

class mySuperClass { public $errors = array(); private function ffff() { $this->errors[] = "error 1"; } private function aaaa() { $this->errors[] = "error 2"; } public function errorsShow() { var_dump($this->errors); } } $myVar = new mySuperClass(); function errorsCollector() { $myVar->errorsShow(); } 

An example of what is above. Does not work

update, real example:

 class loginAuthClass{ // Фильтруем данные private $authStatus = false; // Статус авторизации пользователя в системе public $errors = array(); // Коллектор ошибок выводит ошибки в определенном методе protected function filterGlobalData($string,$ext_filter=false,$min=3,$max=32){ if (empty($string)){ $this->errors[] = "Переменная пустая!"; return false; } // Если задается массив для фильтрации, то фильтруем его if ( is_array($string)){ foreach ($string as $key => $value) { $string[$key] = htmlspecialchars(strip_tags(stripslashes(trim($value)))); } } else { $string = htmlspecialchars(strip_tags(stripslashes(trim($string)))); if ( $ext_filter == true){ if ( strlen($string) < $min || strlen($string) > $max || !preg_match("/^[a-zA-Z0-9]+$/", $string) ) { $this->errors[] = "Неправильные символы или максимальное или минимальное число превышено!"; return false; } } } return $string; } public function authAction(){ /* * ---------------------------------------------------------- * Авторизация сравнивает куки с данными из базы данных и * устанавливает новое время куки для последующей авторизации * Если куки не присутствуют, то возвращает false! * ---------------------------------------------------------- */ $authData['user_id'] = false; $authData['user_hash'] = false; // ----------------------------- // Проверяем куки у пользователя // ----------------------------- if ( isset($_COOKIE['cookie_user_id']) && isset($_COOKIE['cookie_user_hash']) and !empty($_COOKIE['cookie_user_id']) && !empty($_COOKIE['cookie_user_hash']) ) { $authData['user_id'] = $this->filterGlobalData($_COOKIE['cookie_user_id']); $authData['user_hash'] = $this->filterGlobalData($_COOKIE['cookie_user_hash']); }else{ return false; // Возвращаем false потому, переменные для сравнения пустые или остутсвуют } // ----------------------------- // Сравниваем данные пользователя с базой // ----------------------------- $query = "SELECT `userhash`, `username` FROM `users` WHERE `user_id`='".$authData['user_id']."' LIMIT 1"; if ( ($result = mysqli_query($query)) == true){ $result = mysqli_fetch_assoc($result); // Сравниваем хеш куки и пользователя найденного в базе! if ($result['userhash'] === $authData['user_hash']){ // ---------------------------------- // Устанавливаем новое время для куки // ---------------------------------- # code.... $this->authStatus = true; } } return false; } public function loginAction(){ if ( $authStatus == true) return true; // выходим из логинФормы $authLoginData['login_user_name'] = false; $authLoginData['login_user_password'] = false; if ( isset($_POST['username']) && isset($_POST['userpassword']) ) { $authLoginData['login_user_name'] = $this->filterGlobalData($_POST['username'],$ext_filter=true,$min=4,$max=32); $authLoginData['login_user_password'] = $this->filterGlobalData($_POST['userpassword'],$ext_filter=true,$min=4,$max=32); } if ( $authLoginData['login_user_name'] != false && $authLoginData['login_user_password'] != false) { $this->errors[3] = "Результат фильтрации"; return true; } } public function TooltipViewAction(){ echo "<br>all errors-----------------------<br>"; var_dump($this->errors); echo "<br>all errors-----------------------<br>"; } } 
  • How do you call class methods? How exactly does not work - errors, blank screen? - u_mulder
  • First, I declare a new instance of the class in a variable, and then from a variable of the type $ peremenaja-> Metod_iz_klassa (), the var_dump constantly returns 0. array (0) {} - jcmax
  • I repeat the question - How do you call class methods? - u_mulder
  • $ mainAuthClass = new loginAuthClass (); define ("AUTH_STATUS", $ mainAuthClass-> authAction ()); $ mainAuthClass-> TooltipViewAction (); Errors should appear in TooltipViewAction (); like that! - jcmax
  • Listen, you describe one class in a question, another in the comments. Let's decide which class doesn’t work for you and provide its code. - u_mulder

0