Php: how to capture error reports?
<p>I am working on a php script that that is invoked by ajax request, and is supposed to echo some response code to be parsed.</p>

<p>For example:</p>

<pre><code>die('#1:200|Success|'.$data);
</code></pre>

<p>Or another one:</p>

<pre><code>die('#0:100|Access Denied|');
</code></pre>

<p>Now, I want also to include any errors or warnings that might have occurred during the execution of the script - BUT appended at the end of the message.</p>

<p>So, what would be an elegant way of capturing all the errors into some variable?</p>

<p><strong>EDIT</strong></p>

<p>Well It isn't easy to understand how it meant to be used, the manual isn't clear on many things.</p>

<p>But ok, I will try to make an example of how I understand it, then please point it out if I'm getting it wrong :-)</p>

<pre><code>//So guess first I off error reporting that would naturally occur.
error_reporting(0);

//Then I will define array to stuff the errors in.
$errors=array();

//Then I make my handler function.
function handler($errno,$errstr){
    global $errors;
    $errors[]=$errno.': '.$errstr;    //Stuff it into array.
}

//Then I define handler.
set_error_handler('handler',E_ALL);
</code></pre>

<p>Is this correct usage? </p>

<p>It also says:</p>

<p><code>The following error types cannot be handled with a user defined function: E_ERROR, E_PARSE, E_CORE_ERROR, E_CORE_WARNING, E_COMPILE_ERROR, E_COMPILE_WARNING, and most of E_STRICT raised in the file where set_error_handler() is called.</code></p>

<p>And also question, why it wouldn't capture strict errors? </p>
