Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

exit php function with fatal error

Tags:

php

I have a basic if-then-else statement to catch an "exception" but I can not do much in case the exception happens so I would like to exit my script at this point with a fatal error. How can I do this? The code is:

if(ksort($hFileList)) $fileList = array_values($hFileList);
else ???

That is: I am duing all I can to ensure my $hFileList is there and looks as it should, but in case something unexpected happens, I would like to produce a standard php fatal error. Shall I simply get rid of the if and let it "crash" instead?

like image 950
rodedo Avatar asked Sep 13 '26 08:09

rodedo


1 Answers

just put a call to phps trigger_error method:

if( true === $errorCase ) {
    trigger_error( $yourErrorMessage, E_ERROR );
}

that'll stop your script with a fatal error. see php documentation also:

http://php.net/manual/de/function.trigger-error.php

like image 64
ghost_inc_de Avatar answered Sep 15 '26 22:09

ghost_inc_de



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!