tags:

views:

49

answers:

3

What are the best resources do you recommend for learning php debugging?

Is there any specific book, screencast, blog post or article that you really found useful?

A: 

old good article from IBM DeveloperWorks
http://www.ibm.com/developerworks/library/os-debug/

Though the main idea of debugging is quite simple: you have to understand what your program does. And when something goes wrong, you have to do just step-by-step checking, stopping at certain points, checking values of variables. This way you can determine a problem part.
And system error messages always to help too.
That's all.

Col. Shrapnel
+2  A: 

Here's a list of what I could find in a quick google search. The second link is software, the rest are articles except from the last two which are videos. I personally liked the last one since it uses Np++ and Xdebug.

Anyway, most of the time all you need to do is keep your code readable and name your variables and functions correctly, don't be afraid of using long names for them like $arr_dates_meetings instead of $meetings. It will decrease your mistakes since you will locate problems easier. Also make sure that while developing you keep track of the values of your declared variables. Maybe use something like get_defined_vars() to return them all, or just the ones that interest you.

The video I mentioned is rather slow paced so you're probably better off just checking the article it's based on: Debugging PHP using Xdebug and Notepad++

thisMayhem
Thanks for the old Sklar's article, never seen it before
Col. Shrapnel
My pleasure to help
thisMayhem
A: 

I really find useful the following function:

function echo_r($x){
    echo '<pre>';
    print_r( $x );
    echo '</pre>';
}

While far from a debugger, it's really useful for inspecting variables. Using it I hardly ever need a real debugger, i just sprinkle the code where I need to inspect and hit reload.

There is also var_dump but I prefer the first approach.

function echo_r($x){
    echo '<pre>';
    var_dump( $x );
    echo '</pre>';
}
clyfe
var dump is surely better for `debugging` purposes as in include variable type in it's output
Col. Shrapnel