Solved

Code/debug php code

Posted on 2014-11-18
11
200 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
0
Comment
Question by:AXISHK
  • 3
  • 3
  • 2
  • +2
11 Comments
 
LVL 35

Expert Comment

by:Kimputer
ID: 40449204
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).
0
 

Author Comment

by:AXISHK
ID: 40449215
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
0
 
LVL 35

Assisted Solution

by:Kimputer
Kimputer earned 100 total points
ID: 40449271
Notepad++ is editing only. Debugging happens only in the live environment by watching the print codes you have in your php code. If you need to trace through multiple php files, have the print codes there too (for example printing the session variables).
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 40449289
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".
0
 

Author Comment

by:AXISHK
ID: 40449300
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
0
 
LVL 35

Expert Comment

by:Kimputer
ID: 40449309
Yes correct.
0
 
LVL 83

Assisted Solution

by:Dave Baldwin
Dave Baldwin earned 100 total points
ID: 40449328
I often leave my troubleshooting code in the file but commented out when it runs properly.  I might need it again when my customer wants some more changes.  Since PHP is interpreted, you can edit, upload, and run it very quickly.  Or when you have the web server on your machine, you can just edit it and run it.  Which I'm about to do to figure out why one of my programs is not running exactly right.
0
 
LVL 109

Accepted Solution

by:
Ray Paseur earned 300 total points
ID: 40449561
Some good "getting started" concepts and resources are in this article.
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_11769-And-by-the-way-I-am-new-to-PHP.html

In the world of IDEs, Komodo and Eclipse come to mind.  But that said, I do what DaveBaldwin and many other professionals do - we write the code by hand and use var_dump() to visualize the data, step-by-step as we develop the application.  I rarely write more than a few lines of code without testing.  Test-driven development saves so much time you will be amazed!
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_7830-A-Quick-Tour-of-Test-Driven-Development.html
0
 

Author Closing Comment

by:AXISHK
ID: 40461172
Tks
0
 

Expert Comment

by:robin811
ID: 40493972
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;
0
 
LVL 109

Expert Comment

by:Ray Paseur
ID: 40495335
@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
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

As a database administrator, you may need to audit your table(s) to determine whether the data types are optimal for your real-world data needs.  This Article is intended to be a resource for such a task. Preface The other day, I was involved …
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

860 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question