Error Handling in simple_html_dom.php
<p>I am a beginner in PHP and I have a similar problem to that handled in:</p>

<p><a href="http://stackoverflow.com/questions/3431169/good-error-handling-with-file-get-contents">Good error handling with file_get_contents</a></p>

<p>In simple_html_dom.php, there is a function called load_file, which is:</p>

<pre><code>    function load_file() {
    $args = func_get_args();
    $this-&gt;load(call_user_func_array('file_get_contents', $args), true);
    }
</code></pre>

<p>In my PHP script, I use this function as:</p>

<p>$html->load_file($link);</p>

<p>When I try to load a broken link, I get a warning message on my output display like:</p>

<p>Warning: file_get_contents(http://www.yurowdesigns.com/UkraineSIG/test.asp) [function.file-get-contents]: failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found in /home/yurow/wwwroot/yurowdesigns.com/programs/simple_html_dom.php on line 568</p>

<p>I would like to re-route this and similar error messages to an error.log file on my website rather than having it on my output display.</p>

<p>I naively tried to adapt the answer given in</p>

<p><a href="http://stackoverflow.com/questions/3431169/good-error-handling-with-file-get-contents">Good error handling with file_get_contents</a></p>

<p>to my problem by adding the the function fget_contents() to my copy of simple_html_dom.php.</p>

<pre><code>function fget_contents() {
$args = func_get_args();
// the @ can be removed if you lower error_reporting level
$contents = @call_user_func_array('file_get_contents', $args);

if ($contents === false) {
    throw new Exception('Failed to open ' . $file);
} else {
    return $contents;
}
}
</code></pre>

<p>And changed line 568 in load_file to read:</p>

<p>$this->load(call_user_func_array('fget_contents', $args), true);</p>

<p>But now, when I run my PHP script, I get a new error message:</p>

<p>Warning: call_user_func_array() expects parameter 1 to be a valid callback, function 'fget_contents' not found or invalid function name in /home/yurow/wwwroot/yurowdesigns.com/programs/simple_html_dom.php on line 568</p>

<p>Which means that simple_html_dom.php does not recognize the function 'fget_contents'</p>

<p>Where did I go wrong? How can I fix it?</p>
