|
Posted by 703designs on October 8, 2008, 12:02 pm
Please log in for more thread options
Thanks Alvaro, that makes perfect sense. This is for only my own use,
mainly to catch missed includes (for wireframing), but I'll certainly
look into making it @-safe, which seems like an interesting topic to
me.
Thomas
On Oct 8, 11:05=A0am, "=C1lvaro G. Vicario"
> 703designs escribi=F3:
>
>
>
> > How can I add a a row for every error? I know I did this before, but
> > lost the code. The reason that this is necessary: I want errors to
> > build into a table which is positioned absolutely (bottom: 1em; left:
> > 1em). I can only have one copy of the table, otherwise errors overlap
> > each other.
> > <?php
> > $errors =3D "<table class=3D'phpError'>"
> > =A0 =A0 . "<tr><th>Level</th><th>Error</th><th>File</th><th>Line</th></=
tr>";
> > $errorCount =3D 0;
>
> > function golondrinaErrors($number, $string, $file, $line) {
> > =A0 =A0 global $errors;
> > =A0 =A0 global $errorCount;
> > =A0 =A0 $errorCount++;
> > =A0 =A0 $errors .=3D =A0"<tr><td>" . $number . "</td>"
> > =A0 =A0 =A0 =A0 . "<td>" . $string . "</td>"
> > =A0 =A0 =A0 =A0 . "<td>" . $file . "</td>"
> > =A0 =A0 =A0 =A0 . "<td>" . $line . "</td>"
> > =A0 =A0 =A0 =A0 . "</tr>";
> > =A0 =A0 return true;
> > }
> > if($errorCount > 0) {
> > =A0 =A0 $errors .=3D "</table>";
> > =A0 =A0 echo $errors;
> > }
>
> > set_error_handler('golondrinaErrors');
>
> What this code seems to do is:
>
> 1. Set error count to zero
> 2. Print errors if error count is greater than zero
> 3. Tell PHP to user your custom error handler
> 4. Increase the error count when new errors found
>
> You'd need to move the "print errors" part to the end of your script so
> it has the chance of catching some errors before printing them.
>
> Also, be aware that your error handler doesn't honor the @ operator and
> it never aborts the script no matter the error type (might be what you
> want or not).
>
> --
> --http://alvaro.es- =C1lvaro G. Vicario - Burgos, Spain
> -- Mi sitio sobre programaci=F3n web:http://bits.demogracia.com
> -- Mi web de humor al ba=F1o Mar=EDa:http://www.demogracia.com
> --
|