PHP using exit ()

I use Cakephp, but this is MVC / php doubt

letting the view display the message

against

echo 'Invalid Data'; exit;

I would like to know if there are any pitfalls in the second case, such as memory leak, etc. Which one is better

EDIT

In the case of ajax call, we exit well. and what about memory leaks and other issues. All variables are redistributed

+3
source share
4 answers

ExceptionHandler (set_error_handler/set_exception_handler) , - (CakePHP ExceptionHandler). , ExceptionHandler/ErrorHandler , , .

. , , , ( ).

+6

Cake - .

"" , , 404 , , , . :

function view($id) {
    $data = $this->Model->read(null, $id);
    if (!$data) {
        $this->cakeError('error404');
    }

    ...
}

. CakePHP.

POST $this->Session->setFlash('Error!') . .

script exit .

+3

, exit. exit , . , - , , .. , , .

0

(AJAX cals)

Use exit().


user experience (standard nav site)

Show the error on the corresponding page that is stored on your site.

0
source

Source: https://habr.com/ru/post/1765967/


All Articles