How to deliberately cause a fatal error in a PHP script?

I want the script to stop executing at the time of failure, and not to release memory or otherwise destroy the server.

Any idea how to do this?

+5
source share
2 answers

I believe this is what you are looking for:

trigger_error("Oops!", E_USER_ERROR); 

Docs: http://php.net/manual/en/function.trigger-error.php

E_USER_ERROR is pretty much equal to E_ERROR, which is a fatal execution error .

+8
source

A bit late, but this is a guaranteed natural fatal error:

Call the undefined function, for example:

 noSuchFunction(); 

Or if you want this to be executed when you are only in test mode, and then put it in eval

 if($isTestMode==1){ eval("noSuchFunction();"); } 

Edit: with the trigger_error () function, the problem is that if you use set_error_handler (), it ceases to be fatal - your error handler will decide what to do with it.

+7
source

All Articles