Re: debugging

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



William Stokes wrote:
> I would like to add some debugging/info code to my pages. In test
> environment of course. Any ideas how to do this? I mean for example to
> print
> to a web page the line number when the script fails or something like
> that.
> It's a pain on the **s to hunt typo's by just reading the source over and
> over again.

http://php.net/set_error_handler

is what you need.

Also use http://php.net/error_log to send all errors to a log file
(default, the Apache log file) so you do *NOT* display them on the
production server, even if somebody screws up php.ini, or installs a new
PHP which expects php.ini in a different place, or...

Note that your set_error_handler is given the filename and line number as
arguments.  Use them in your output.

Finally, start using http://php.net/trigger_error insead of 'die' in your
scripts, and add as MUCH error-checking of return values as you can.

EVERY function that can return an error code, or set an error message
should be checked EVERY time you call it.

You cannot imagine how much simpler your debugging life will be when you
do this, and it's not any tougher than typing "or die()" all the time, and
not really that hard to write a couple extra lines of boiler-plate code
after every function call.

-- 
Like Music?
http://l-i-e.com/artists.htm

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux