Hi,
I maid the modifications you suggested. For the error
context when i display it, it gives a lot of
information, but not easy to understand how the array
is structured. If somebody knows about a site
explaining how to access the context it would be
great.
I also modified the error reporting to E_ALL as you
suggested. Now an other question arise: For the
connection to the database if i put a wrong username
or password the error is reported automatically to the
function that i defined as the error handling
function, but for the next statement (see code below)
if i put a wrong database name the error is not
reported automatically, i have to trigger it using
triger_error. So i'm wondering if there are some rules
that can help me know if an error will be reported
automatically or not. here is my code after
modification:
<?php
function error_handler($errno, $errstr, $filename,
$lineno, $errcontext)
{
echo "handling reported error<br>";
switch($errno) {
case E_USER_ERROR: $type =
"E_USER_ERROR";break;
case E_USER_WARNING: $type =
"E_USER_WARNING";break;
case E_USER_NOTICE: $type =
"E_USER_NOTICE";break;
case E_ERROR: $type = "E_ERROR";break;
case E_WARNING: $type = "E_WARNING";break;
case E_PARSE: $type = "E_PARSE";break;
case E_NOTICE: $type = "E_NOTICE";break;
case E_CORE_ERROR: $type = "E_CORE_ERROR";break;
case E_CORE_WARNING: $type =
"E_CORE_WARNING";break;
case E_COMPILE_ERROR: $type =
"E_COMPILE_ERROR";break;
case E_STRICT: $type = "E_STRICT";break;
case E_COMPILE_WARNING: $type =
"E_COMPILE_WARNING";break;
case E_RECOVERABLE_ERROR: $type =
"E_RECOVERABLE_ERROR";break;
default: echo "<br>This is an error not listed";
}
$str = "";
$str .= "<br><br>ERROR TYPE: ". $type;
$str .= "<br><br>ERROR Number: ". $errno;
$str .= "<br>ERROR MESSAGE: ". $errstr;
$str.= "<br>File: ". $filename;
$str.= "<br>Line number: ". $lineno;
echo $str;
echo "Context: <br>";
print_r($errcontext);
}
echo "<h1>Testing set_error_handler</h1>";
error_reporting(E_ALL);
set_error_handler('error_handler');
mysql_connect("localhost", "admin", "admin");
mysql_select_db("wrongdb") or trigger_error("wrong
database");
?>
--- Jim Lucas <[EMAIL PROTECTED]> wrote:
> It Maq wrote:
> > Hi,
> >
> > i need help because I'm unable to retrieve error's
> context. Below is the code that is working perfectly
> except the context that is not displayed:
> >
> > <?php
> > function error_handler($errno, $errstr,
> $filename, $lineno, $errcontext)
> > {
> >
>
> try doing a print_r($errcontext) here and see what
> you get?
>
> maybe the zero index does not exist.
>
> >
> > $str = "";
> > $str .= "<br><br>ERROR Number: ". $errno;
> > $str .= "<br>ERROR MESSAGE: ". $errstr;
> > $str.= "<br>File: ". $filename;
> > $str.= "<br>Line number: ". $lineno;
> > $str.= "<br>Context: ". $errcontext[0];
> > echo $str;
> >
> >
> > }
> >
> > echo "<h1>Testing set_error_handler</h1>";
> >
>
> I have always used
> error_reporting(E_ALL);
> instead of this.
> > error_reporting(0);
> > set_error_handler('error_handler');
> > ini_set('error_reporting', 0);
>
> I have never seen the above line before. This and
> the error_reporting(0) would
> probably suppress all error messages generated by
> PHP. Double check these
> settings and make sure the you can still trigger an
> error with trigger_error()
> if you have error_reporting() turned off.
>
> >
> > //trigger_error("The string for testing the
> error", E_USER_WARNING);
> > $ourFileName = "testFile.txt";
> > $fh = fopen($ourFileName, 'X');// or die("Can't
> open file");
> > fclose($fh);
> >
> >
> > ?>
____________________________________________________________________________________
Be a better friend, newshound, and
know-it-all with Yahoo! Mobile. Try it now.
http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php