We help IT Professionals succeed at work.

Code/debug php code

AXISHK
AXISHK asked
on
238 Views
Last Modified: 2014-12-11
I have installed WAMP server with php, MySQL. Which tool should I install in order to debug and modify the php code ? Any simple guideline on this ?

Tks
Comment
Watch Question

KimputerIT Manager
CERTIFIED EXPERT

Commented:
Depending on your problems, you should use print_r commands on various tacticallly sound spots in your php code (so it depends on your errors and what you're trying to debug). If used properly, you can "trace" a variable, and notice where it changes or behaves unexpectedly, and that's usually where the bug is (wrong formula, wrong logic, etc). I prefer Notepad++ for php editing (unless you already have a more expensive software package like Dreamweaver).

Author

Commented:
Notepad++ don't have debugging feature, and we need to use print_r commands to list the variable, correct ?

How to use notepad++ to trace through ,say a.php -> b.php -> c.php.  Any example on this ?

Tks
KimputerIT Manager
CERTIFIED EXPERT
Commented:
This problem has been solved!
(Unlock this solution with a 7-day Free Trial)
UNLOCK SOLUTION
Dave BaldwinFixer of Problems
CERTIFIED EXPERT
Most Valuable Expert 2014

Commented:
I do like @Kimputer says.  I just use my code editor and put in 'echo' and 'print_r' statements (temporarily) where I need to find out what's going on..  I have never had an IDE with a "debugger".

Author

Commented:
Do you mean simply modify the php code to print out some variables ? Run the php website again to dump the result. Afterwards, remove the code, correct ?

Tks
KimputerIT Manager
CERTIFIED EXPERT

Commented:
Yes correct.
Dave BaldwinFixer of Problems
CERTIFIED EXPERT
Most Valuable Expert 2014
Commented:
This problem has been solved!
(Unlock this solution with a 7-day Free Trial)
UNLOCK SOLUTION
Most Valuable Expert 2011
Author of the Year 2014
Commented:
This problem has been solved!
(Unlock this solution with a 7-day Free Trial)
UNLOCK SOLUTION

Author

Commented:
Tks

Commented:
It's often useful to follow the print_r or var_dump line with the command die.  If there is an http request after the var_dump, the output can be  overwritten before you can see what it is.  the die command stops execution so you can see your var_dump output.

I use a macro that outputs the following code (inserting the contents of the clipboard in the parentheses, I copy the name of the variable I want to dump first, then run the macro):

/*DELETE*/ echo var_dump($request); die;
Most Valuable Expert 2011
Author of the Year 2014

Commented:
@robin811: Good advice!  Laravel has a dd() function that does a "var_dump(); die()" sequence.  Very helpful for isolating that one nagging thing!  Best to all, ~Ray