Click to See Complete Forum and Search --> : How to find bugs in PHP applications (before posting here)


MarkR
04-01-2006, 05:09 AM
Most problems are caused by the developer doing something wrong. With this in mind, before posting here, you should:

1. Set up error_reporting(E_ALL). Ensure that errors are always displayed (safe for development environments only) or logged (safe anywhere). Read the log files. DO NOT suppress errors with the @ operator for functions likely to fail (mysql_connect, mysql_query() etc.).

If, upon turning on error_reporting(E_ALL), you get 1 bazillion* notices / warnings on your error log, please fix those faults immediately, then try again.

2. Try to diagnose where the fault happens. If it stops part way through the expected execution of the script, try to find out where. Either use a PHP debugger, or echo, or error_log() to determine where the fault is (if you can't get the error with error_reporting)

3. If you MUST post here, record all relevant details:

- Versions of PHP, web server, web browser, and if databases are involved, the database
- All error messages appearing on the error log, or those produced by the browser.
- What the expected behaviour of your code is. Maybe some of us are telepaths who can figure out what you're trying to do, but I'm not :)

4. If you're going to quote bits of code, use php tags. Don't paste more than about 20-30 lines however, because people will not want to trawl through your code.

5. Don't post anything security-critical! This includes passwords, production data, core dumps, error logs which might contain anything important (i.e. from production servers)

Cheers

Mark

* lots

rincewind456
04-01-2006, 05:43 AM
I'd just like to add before stage 3.

At the very least search this forum, as the most common errors have been covered here ad nauseum.

Jason Batten
04-01-2006, 05:52 AM
Trial and error. I try my code after almost every chunk, even if I am 99% sure it will work.

RTFM. "Do it."

Google.

Be impatient. People take too long to reply, so why bother? ;)

Weedpacket
04-01-2006, 07:07 AM
Have a look too at the suggestions in the Debugging 101 (http://www.phpbuilder.com/board/showthread.php?t=10240608) thread in the Echo Lounge for more debugging suggestions, and the General Bulletin Board Guidelines (http://www.phpbuilder.com/board/showthread.php?t=10218925) in the Newbies forum for guidelines about posting.

vaaaska
04-01-2006, 12:02 PM
MarkR forgot to include '6. Swear at your computer until you feel that you are in control of the situation'.

;)

Jason Batten
04-01-2006, 12:13 PM
The Reset Button is the power :)

Show that PC who's boss!