How to intentionally cause a fatal error in PHP script?

Bit late but this is a guaranteed natural fatal error:

Call an undefined function, eg:

noSuchFunction();

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

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

Note: With the trigger_error() function the problem is that if you are using set_error_handler() it ceases to be fatal - your error handler will decide what to do with it.


I believe this is what you're 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 runtime error.

Tags:

Php

Crash