Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Trigger fatal error in PHP 7 (non-exception)

I need to be able to trigger a fatal error in PHP 7 that is not thrown as an exception.

According to the PHP docs, most of the fatal errors have been converted to exceptions. However, I can't find any docs on which ones were and were not converted.

My Question: What is something I can do in PHP to trigger one of the fatal errors that has not been converted to an exception?

Reason: I am developing a universal error handler for an API based application. I need a test case to prove it will work as I say it does.

like image 988
Nicholas Summers Avatar asked Apr 24 '26 19:04

Nicholas Summers


1 Answers

You can trigger a fatal in a number of ways, calling an undefined function is one such way and pretty simple, e.g.

<?php

foo();
<br />
<b>Fatal error</b>:  Uncaught Error: Call to undefined function foo() in [...][...]:4
Stack trace:
#0 {main}
  thrown in <b>[...][...]</b> on line <b>4</b><br />
like image 154
aland Avatar answered Apr 26 '26 10:04

aland



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!