PHP: Trigger fatal error?

DudeOnRock picture DudeOnRock · Apr 8, 2013 · Viewed 25.5k times · Source

I would like to be able to throw a fatal, uncatchable error in my php class when a user of my class abuses it for something I did not intend. I don't want him/her to be able to recover with a catch clause. I know about trigger_error, but I can only make it issue warnings or notices.

Answer

bwoebi picture bwoebi · Apr 8, 2013

E_USER_ERROR is the suited constant.

trigger_error("Fatal error", E_USER_ERROR);

See also the first example of the manual page and the list of PHP Errors (only ones beginning with E_USER* may be issued from trigger_error).