Best tools for debugging PHP

by 27 replies
33
As PHP is a server side language I'm just wondering is there any way to be able to step through line by line a running PHP program? I'm so used to being able to step through line by line with a programming language like Java, it would be fantastic if it were possible to do this with PHP.

Any other tips for general testing of PHP code?
#programming #debugging #php #tools
  • I know that the IDE NetBeans can debug PHP code. They even have a tutorial on their site.
    Code:
    netbeans.org/kb/docs/php/debugging.html
    I bet other IDEs like Eclipse can also debug code.
  • I'm a fan of Xdebug (Xdebug - Debugger and Profiler Tool for PHP). It makes debugging things much easier, and also integrates with IDE's to provide line by line step throughs. The profiling features are also top notch.
  • Thanks for the suggestions, from looking at netbeans.org/kb/docs/php/debugging.html NetBeans actually needs XDebug to provide line by line debugging. As I am already familiar with NetBeans I will incorporate both of your suggestions :-)
  • Dreamweaver CS5 also has an excellent debugger built in straight out of the box, it highlights all the errors for you and tells you what they are. Although after you've been coding for a year or two you will start just seeing the errors through your supreme nerd-o-vision like I do lol.
  • Banned
    [DELETED]
  • I have little knowledge about php but You can use the Xdebug extension, and Eclipse PDT as IDE : the second one is able to use the first one as debugger.
  • Just wanted to second/third/fourth the XDebug comment. It really is an amazing tool.

    Also bear in mind that you can often do things like this to establish what's gone wrong:

    Code:
    echo print_r(somevariable);
    exit;
    (sorry, code tags don't like the $ symbol!)

    Throw that slap bang in the middle of your code where you think the problem is, and it'll die during the request, neatly spitting out a human-readable form of a variable, object, or array. That may be a little faster than waiting for something to break
    • [1] reply
    • You could add something like this to have the results clearer:

      Code:
      echo "<pre>";
      print_r(somevariable);
      echo "</pre>";
      exit;
      Also, Netbeans rules at debugging.
  • Here list of debugging tools for PHP, among of them are :

    1. webgrind
    2. xdebug
    3. gubed PHP
    4. DBG
    5. PHP debug
    6. PHP dyn
    7. etc

    You can try above PHP tools as you wish.
    • [1] reply
    • Agree with you sir, I'm using wamp server for localhost, webgrind and xdebug is very help me a lot. But don't forget to clear /tmp folder inside wamp directory.

      Recently I was deleted about 70GB files in /tmp directory.
  • No confusion!!!
    Netbean is the one. That is very easy to use and enriched with so many features.
    So my vote is for netbean.
  • Hello friv. You should enable error_reporting
    Php code: error_reporting(1);
  • Xdebug, PHP debug and PHP dyn.
    I just know about those. you can try those tools to debug php.
    may be it'll help you out.
  • They pretty much listed all the tool.
    I also integrate this function to my code to debug fast:
    function debug($label, $data) {
    echo "<div style=\"margin-left: 40px;\"><u><h3>".$label."</h3></u><pre style=\"border-left:2px solid #000000;margin:10px;padding:4px;\">".print_r($data , true)."</pre></div>";
    }

    use like this:
    debug("any text", $var);
  • I've found the best way to do debugging is by adding catch and debug statements in the code so you know where the code is going and why.
  • I use NetBeans with xDebug .Makes the uncomfortable debugging a breeze.
  • Banned
    [DELETED]
    • [1] reply
    • I think netBeans uses xDebug by default.

      So if you use netBeans and a have a project open - just start debugging. If something is wrong, netBeans will let you know.
      • [1] reply
  • Even a Dreamweaver can debug PHP
  • It's been a while since I've done any PHP programming, mostly Rails these days, but I always used Firebug+FirePHP to debug a running app. If you're doing object-oriented PHP (especially using an MVC framework like CodeIgniter) you should also be using a unit testing framework like PHPUnit. Not the same as debugging, but it'll help you find a lot of problems with your code before you deploy it to a live site.
  • I am using Dreamweaver to debug PHP script ,but it is not like java editor .You need little knowledge about Dreamweaver,otherwise debugging may be complex to you.
  • Banned
    "notepad++" I am using it right now.
    You can choose "aptana studio",
    but the best tool is "Dreamweaver".
  • Xampp is best for development or you may use Wamp but I could recommend you to use Xampp.It's very easy to easy & has lots of features.
  • I like Jetbrains PHPStorm alot, bit expensive though...I think it's the best at charting the includes and functions across the filesystem though.
  • I use Eclipse PHP, and of course, debug options in wordpress/drupal.
    Tried Zend before but I personally felt it's too much. On my second screen: php error logs, apache access, apache error, apache rewrite. That's more than enough =)
    • [1] reply
    • Call me old fashion but i'm using NotePad++ and checking the logs from my server before going to production..
  • Banned
    [DELETED]
  • Banned
    [DELETED]
  • I use Codelobster to debug PHP code.
    It is free and works very well for me.
  • [DELETED]

Next Topics on Trending Feed

  • 33

    As PHP is a server side language I'm just wondering is there any way to be able to step through line by line a running PHP program? I'm so used to being able to step through line by line with a programming language like Java, it would be fantastic if it were possible to do this with PHP. Any other tips for general testing of PHP code?