|
Home | Switchboard | Unix Administration | Red Hat | TCP/IP Networks | Neoliberalism | Toxic Managers |
(slightly skeptical) Educational society promoting "Back to basics" movement against IT overcomplexity and bastardization of classic Unix |
Komodo IDE | Humor | Random Findings | Etc |
|
|
PHP does not have built-in debugger and as such is inferior scripting language to Perl, Python and Ruby. When push comes to shove, the simple fact is that almost anyone can learn the syntax and grammar of PHP well enough to write programs. However, as applications and projects become larger, the method of finding errors provided by the language became as important as the language itself. PHP sucks in this respect. It is inferiour language. No question about it.
The most well know debugger for PHP is DBG debugger. There are several external tools that are based on DBG debugger. They include Dev-PHP , Komodo and Eclipse.
Another free PHP debugger is Gubed and PECL. The latter is a full-featured profiler/debugger that is loaded as a zend_extension. It aims to be an analog of C's gprof or Perl's Devel::DProf.
Xdebug is debugger based of Xdebug protocol. Xdebug 2 is a true multi-language protocol. This means that a client written for Xdebug 2 will also work in combination with the Perl, Python, Tcl and XSLT debuggers from Active State. For a description of (a draft) of this new protocol, see the documentation - protocol page. The development of the protocol is sponsored by Maguma and will also be implemented in Maguma Studio 2.
PSD - A visual frontend for debugging PHP. It runs on Win98SE and newer and can be used remotely. [Freeware]
|
Switchboard | ||||
Latest | |||||
Past week | |||||
Past month |
Discover five common database problems that occur in PHP applications -- including database schema design, database access, and the business logic code that uses the database -- as well as their solutions.
Explore various methods for debugging PHP applications, including turning on error reporting in Apache and PHP, and by placing strategic print statements to locate the source of more difficult bugs through a simple example PHP script. The PHPeclipse plug-in for Eclipse, a slick development environment with real-time syntax parsing abilities, will also be covered, as well as the DBG debugger extension for PHPeclipse.
Whether you're a PHP newbie or a wizard, your programs are going to have bugs in them. Nobody's perfect. This article gives you some techniques for finding and fixing the problems in your programs. It covers three topics:
- How to get the PHP interpreter to report the errors that interest you.
- How to locate basic syntax errors in your program.
- How to check the values of variables as your program is running.
Configuring Error Reporting
First of all, you need to configure the PHP interpreter so that when an error happens, you can see information about it. The error info can be sent along with program output to the web browser. It can also be included in the web server error log. A common way to set things up is to have error output go to the web browser when you're debugging your program, and then to the web server error log once the program is finished and (supposedly) working properly. That way, web site users can't see any potentially sensitive data included with error output.
To make error messages display in the browser, set the
display_errors
configuration directive toOn
. To send errors to the web server error log, setlog_errors
toOn
. You can set them both toOn
if you want error messages in both places.An error message that the PHP interpreter generates falls into one of five different categories:
- Parse error: A problem with the syntax of your program, such as leaving a semicolon off of the end of a statement. The interpreter stops running your program when it encounters a parse error.
- Fatal error: A severe problem with the content of your program, such as calling a function that hasn't been defined. The interpreter stops running your program when it encounters a fatal error.
- Warning: An advisory from the interpreter that something is fishy in your program, but the interpreter can keep going. Using the wrong number of arguments when you call a function causes a warning.
- Notice: A tip from the PHP interpreter, playing the role of Miss Manners. For example, printing a variable without first initializing it to some value generates a notice.
- Strict notice: An admonishment from the PHP interpreter about your coding style. Most of these have to do with esoteric features that changed between PHP 4 and PHP 5, so you're not likely to run into them too much.
You don't have to be notified about all of the different error categories. The
error_reporting
configuration directive controls which kinds of errors the PHP interpreter reports. The default value forerror_reporting
isE_ALL & ~E_NOTICE & ~E_STRICT
, which tells the interpreter to report all errors except notices and strict notices.PHP defines some constants you can use to set the value of
error_reporting
so that only errors of certain types get reported:E_ALL
(for all errors except strict notices),E_PARSE
(parse errors),E_ERROR
(fatal errors),E_WARNING
(warnings),E_NOTICE
(notices), andE_STRICT
(strict notices).Because strict notices are rare (and new to PHP 5), they are not included in
E_ALL
. To tell the PHP interpreter that you want to hear about everything that could possibly be an error, seterror_reporting
toE_ALL | E_STRICT
.
About the debugger
- Table of Contents
- About the debugger
- Using the Debugger
- Debugger Protocol
PHP 3 includes support for a network-based debugger.
PHP 4 does not have an internal debugging facility. You can use one of the external debuggers though. The Zend IDE includes a debugger, and there are also some free debugger extensions like DBG at http://dd.cron.ru/dbg/, the Advanced PHP Debugger (APD) or Xdebug which even has a compatible debugger interface as PHP 3's debugging functionality as is described in this section.
add a note User Contributed Notes
Debugging PHP 13-Sep-2006 09:51NuSphere Php IDE PhpED (www.nusphere.com) includes dbg from dd.kron.ru actually
online _ use _ only == hotmail.com
15-Mar-2006 04:41I still find that printing out variable values at problem points in the code is one of the easiest ways for me to debug. If you're interested in knowing the full contents of an object/array/scalar, then use
linus at mccabe dot nuvar_dump($var).
24-May-2004 02:04Another free (GPL) debugger is Gubed, http://gubed.sf.net .
tulpe at atomar dot de
Currently available for Linux, but also Windows soon.
07-Feb-2003 08:09Tired of manualy printing out your variables and arrays for debugging?
joe_fitchnospam at hotmail dot comTake a look at my debuglib at:
http://www.atomar.de/public/code/debuglib/debuglib.demo.php
Happy debugging!
Thomas Sch?/span>
17-Dec-2002 01:15I've tried many debuggers and PHP IDEs including Zend IDE, Komodo, PHPEdit, PHPEd and Maguma Studio.
23-Aug-2002 12:51
After all I'm sure that the best one debugger is dbg. It supports breakpoints even conditional ones, all kind of steps throu php code, watch etc, so it's a fully functional debugger indeed and profiler too. Fortunately, it's an open-source product as PHP itself. Unfortunately, it does not contain any front-end, but 3rd party PHP IDEs. Seems, as for an IDE the best one is PHPEd 3.1 (http://www.phped.com), former PHP IDE from Ergin Soysal.
I was also deeply impressed with IonCube accelerator performance (http://www.ioncube.com). Commercial version of IONCUBE is many times faster than the commercial one from Zend (www.zend.com). Huh ?
Hope this info would help someone to find the better way faster.
check out this great, cross-platform, my favourite php debugger:
http://www.activestate.com/Products/Komodo/it not only allows "debugging PHP programs locally or remotely, including debugging in CGI or other Web Server API environments", but, besides, is a full fledged Perl, PHP, Python, Tcl, and XSLT IDE. based on mozilla.
current version 1.2.9 costs some money ($29.50 non commercial), previous version 1.1 is free (non commercial).
Recommended Links
Google matched content
Softpanorama Recommended
Top articles
Sites
PHP Command Line UsePHP has steadily progressed to the stage that command line usage of the PHP.exe is easier than ever before; especially with the new PHP 5 betas. This is most fortunate because it makes testing out little scriptlets of PHP code easier than ever. And with the new OOP and XML capabilities of PHP there are plenty of opportunities to test PHP fast and easily with command line test scripts and even simple batch harnesses that rip through 10 variations on a OOP definition theme. The side benefit ? Users suddenly discover that with regular expressions, great database connectivity, always great file I/O operations, easy array manipulation - in short the whole legacy Perl-like and enhanced features, PHP makes a great OS scripting agent.The figure below shows the command options available when running PHP in command line mode.
SourceForge.net: PHP debugger DBG
DBG is a full-featured PHP Debugger and Profiler. Makes it easier to find problems or bugs in PHP scripts. DBG supports back-tracking, watching variables, viewing arguments passed to all nested function calls at any point of execution. Opensource.
DBG PHP Debugger and Profiler. -- home site of DBG debugger
Debugging techniques for PHP programmers
Zend Technologies - Beginner Tutorials - JavaScript Powered PHP ...
Komodo 3.1 - Online Docs : Debugging PHP
12 Steps to a Bigger, Better, Debugger evolt.org
- "Debugging techniques for PHP programmers"
- Explore various methods for debugging PHP applications, including turning on error reporting in Apache and PHP, and placing strategic print statements to locate the source of more difficult bugs through a simple example PHP script. The PHPEclipse plug-in for Eclipse, a slick development environment with real-time syntax parsing abilities, is also covered, as is the DBG debugger extension for PHPEclipse.
- "PHP Performance Profiling"
- Learn how to use the Advanced PHP Debugger (APD) to profile your PHP code. Code profiling helps you identify bottlenecks or inefficient code in your application, enabling you to tune the code where needed.
- Advanced PHP Debugger
- The Advanced PHP Debugger (APD) is a Zend extension that provides traces suitable for debugging and profiling code, as well as full stack backtrace. Events-based logging is also supported, so different levels of information logging can be set on a script by script basis.
- Xdebug
- Xdebug is an extension that offers debugging information, including full traces and function/line indicators. Xdebug also includes profiling and script execution analysis.
Last updated: March 12, 2019