set_error_handler Isn't Working How I Want It To Work
<p>I'm taking the leap: my php scripts will ALL fail gracefully!</p>

<p>At least, that's what I'm hoping for...</p>

<p>I don't want to wrap (practically) every single line in try...catch statements, so I think my best bet is to make a custom error handler for the beginning of my files.</p>

<p>I'm testing it out on a practice page:</p>

<pre><code>function customError($level,$message,$file,$line,$context){
echo "Sorry, an error has occured on line $line.&lt;br /&gt;";
echo "The function that caused the error says $message.&lt;br /&gt;";
die();
}

set_error_handler("customError");

echo($imAFakeVariable);
</code></pre>

<p>This works fine, returning:</p>

<p>Sorry, an error has occured on line 17.
The function that caused the error says Undefined variable: imAFakeVariable.</p>

<p>However, this setup doesn't work for undefined functions.</p>

<pre><code>function customError($level,$message,$file,$line,$context){
echo "Sorry, an error has occured on line $line.&lt;br /&gt;";
echo "The function that caused the error says $message.&lt;br /&gt;";
die();
}

set_error_handler("customError");

imAFakeFunction();
</code></pre>

<p>This returns:</p>

<p>Fatal error: Call to undefined function: imafakefunction() in /Library/WebServer/Documents/experimental/errorhandle.php on line 17</p>

<p>Why isn't my custom error handler catching undefinedd functions?  Are there other problems that this will cause?</p>

<p>Thanks,
Jason</p>
