V
V
vovkka2018-02-21 09:00:03
PHP
vovkka, 2018-02-21 09:00:03

How to correctly display errors to the user?

Good afternoon. Can you please tell me how to correctly display errors to the user? An example of how I do it:

//создаем массив для ошибок
$errorMessage = [];

if (count($errorMessage)) {
      $errorMessage[] = "Пользователя с такой почтой не существует!";
    }

Well, in fact, all my code boils down to checking the array of errors for emptiness and if there is output, if not, go further. I watched examples, where people write an array of errors to the session, then put exit(); and possibly a redirect. What I don't like about this scheme: An array of errors in the session and after exit() throws on an empty page (if header() is not specified). At the moment, there are not enough skills to write in OOP, so this option is not being considered yet (try catch) Good luck to everyone!

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question