473,396 Members | 2,154 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Debugging PHP

Hi All,
I've just started writing PHP scripts. I was wondering whether there was
any sensible debugging facilities that I'm not aware of. Basically, my usual
development procedure involves writing the script and then testing using IE.
However, it appears that unless the PHP is perfect (ie. devoid of any
syntactical errors) then nothing at all is output to the browser. Personally
I find this very frustrating as there's no clue as to where the error is. I
then commence on a wild goose chase putting in various debugging 'echo'
statements and commenting out various chunks of PHP code until something
works. There must be a better approach than this.

Are there any option or selections I can make to give me some debugging
output?. Is there a parser I can use to ensure there are no syntactical
errors before running the script?. Or a PHP debugger I can use to step
through the code command by command?.

Thanks,
Dave

Jul 17 '05 #1
12 1670
Dave Moore wrote:
Are there any option or selections I can make to give me some debugging
output?


Put this at the top of your PHP script:

error_reporting(E_ALL);

--
phil [dot] ronan @ virgin [dot] net
http://vzone.virgin.net/phil.ronan/
Jul 17 '05 #2
Dave,

Putting error_reporting(E_ALL) directly in your script may not be
necessary. By default, this value is already set in PHP. Use
phpinfo() to find out if it is.

Your best bet is to put in echo, print, or fwrite(for command line
interface) in your script at key points. This will help you "walk"
through it.

There are several IDE's that have debugging capabilities. They may
even be able to run the script or step through it.

There is a free IDE for PHP (http://syn.sourceforge.net/). It is a
decent editor with Syntax highlighting and the such. It also has
debugging capabilities. However, I never had luck getting this aspect
to work and gave up on it. But, it is a decent editor. I would not
that it seems to be a bit of a process and memory hog at random times.

Jul 17 '05 #3
Hi Dave,

The following is not a debugger, but it can be very helpfull nevertheless:
http://nl2.php.net/manual/en/functio...-backtrace.php
feed the array to print_r to see what exactly you get. Then it should
not be hard to build a fancy backtrace printing function.

If you make an error handling function and set its name with
set_error_handler you can make it print a backtrace below the
coventional error info. (search the manual for set_error_handler)

Limitation: it will not work for fatal errors - imho the person that
decided that php developers do not need error handling for fatal errors
made a fatal mistake :-(((

Greetings,

Henk Verhoeven,
www.phpPeanuts.org.

Dave Moore wrote:
Hi All,
I've just started writing PHP scripts. I was wondering whether there was
any sensible debugging facilities that I'm not aware of. Basically, my usual
development procedure involves writing the script and then testing using IE.
However, it appears that unless the PHP is perfect (ie. devoid of any
syntactical errors) then nothing at all is output to the browser. Personally
I find this very frustrating as there's no clue as to where the error is. I
then commence on a wild goose chase putting in various debugging 'echo'
statements and commenting out various chunks of PHP code until something
works. There must be a better approach than this.

Are there any option or selections I can make to give me some debugging
output?. Is there a parser I can use to ensure there are no syntactical
errors before running the script?. Or a PHP debugger I can use to step
through the code command by command?.

Thanks,
Dave

Jul 17 '05 #4
That won't help when there's a parse error. The solution here is to
make sure display_error is set to "on" in php.ini and error_reporting
to something sensible, like E_ALL & ~E_NOTICE.

Jul 17 '05 #5
On 30 Apr 2005 11:26:43 -0700, "Chung Leong <ch***********@hotmail.com>"
<ch***********@hotmail.com> wrote:
That won't help when there's a parse error. The solution here is to
make sure display_error is set to "on" in php.ini and error_reporting
to something sensible, like E_ALL & ~E_NOTICE.


E_ALL is sensible whilst developing; don't turn off E_NOTICE.

--
Andy Hassall / <an**@andyh.co.uk> / <http://www.andyh.co.uk>
<http://www.andyhsoftware.co.uk/space> Space: disk usage analysis tool
Jul 17 '05 #6
On Sat, 30 Apr 2005 20:05:37 +0100, Andy Hassall wrote:
to something sensible, like E_ALL & ~E_NOTICE.


E_ALL is sensible whilst developing; don't turn off E_NOTICE.


Maybe even turn om E_STRICT (not included in E_ALL):

error_reporting = E_ALL|E_STRICT
--
Firefox Web Browser - Rediscover the web - http://getffox.com/
Thunderbird E-mail and Newsgroups - http://gettbird.com/
Jul 17 '05 #7
Zend Studio has an excellent debugger, check it out at:

www.zend.com

Xdebug is your other option, basically both "inject" themselves into
PHP and you (the programmer) can debug via their perspective clients
(which listen for their requests on specific ports on your machine,
different than MS Studio debuggers).

Jul 17 '05 #8
On 1 May 2005 01:27:21 -0700, jo*******@gmail.com wrote:
Zend Studio has an excellent debugger [...] Xdebug is your other option


How about phpeclipse, apparently it includes a debugger (from eclipse,
or php-specific?), do you have any experience with that?
--
Firefox Web Browser - Rediscover the web - http://getffox.com/
Thunderbird E-mail and Newsgroups - http://gettbird.com/
Jul 17 '05 #9
People should use whatever settings that's helpful. Personally I
program with E_WARNING off too.

Jul 17 '05 #10
Dave Moore wrote:
Are there any option or selections I can make to give me some debugging output?. Is there a parser I can use to ensure there are no syntactical errors before running the script?. Or a PHP debugger I can use to step through the code command by command?.


I evaluated NuSphere phped and Zend Studio last year. They both do have
debugging support, but I like phped better. Generally, it's better and
more responsitive while Zend Studio is slow and resource hog. I
purchased phped then and it helps me to write better code.

Both are nice products however, you may want to try them on your
project.

-Erich

Jul 17 '05 #11
Sorry for the late reply.

No unfortunately I do not. I can however tell you that Zend is probably
your best bet as they an inherit better understanding of the Zend
Engine (2), which is a core part of PHP. Because of this fact, I trust
it to be more "up to date" and better supported in terms of future PHP
(I'm a bleeding edge kind of guy, so that might not be the case with
you).

Prices are about the same, I think Zend might provide support longer
support for you though, it's been a while since I checked the pricing
charts though. Well I take that back, I don't really remember as my
company bought the license on my behalf, all I know is that I have had
complimentary product updates thus far. ;-)

The debugger I can compare Zend Studio to is MS Visual Studio, in that
they basically have the same features and interaction (right down to
the shortcut keys if you select the MS VS keyboard layout option).

However, I did run into some trivial problems with getting things
working at home with the debugger, due to my router and some drive
mapping, but at the end I got it working just as I'd like...plus the
Firefox toolbar just seals the deal for me :-)

Zend Enhanced support is really reliable and some of the most
knowledgable people I have worked with in support. I've heard good
things about eclipse from fellow programmers at work, but I couldn't
even get it to start up on my machine so I can't comment personally.

Jul 17 '05 #12
Chung Leong <ch***********@hotmail.com> wrote:
That won't help when there's a parse error. The solution here is to
make sure display_error is set to "on" in php.ini and error_reporting
to something sensible, like E_ALL & ~E_NOTICE.


if you're looking to debug your scripts i strongly advise you to
download Komodo personal, search on the internet, and get a premotion
code and a free copy, works with the dbg debugger and is flawless for me.
Jul 17 '05 #13

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: ZMan | last post by:
Scenario: This is about debugging server side scripts that make calls to middle-tier business DLLs. The server side scripts are legacy ASP 3.0 pages, and the DLLs are managed DLLs...
16
by: Serdar Kalaycý | last post by:
Hi everybody, My problem seems a bit clichè but I could not work around. Well I read lots of MSDN papers and discussions, but my problem is a bit different from them. When I tried to run the...
2
by: Andy Fish | last post by:
Hi, Using VS.NET 2003, when I use 'F5' to start debugging my web app, it obviously attaches the IDE to IIS for server debugging. However, it also seems to put IE into some kind of debugging mode...
2
by: Alex Clark | last post by:
Hi All, My system: WinXP Pro, VS.NET 2003, SQL Server Personal Edition. I'm having problems with my old favourite demon, SQL Debugging from within VS.NET. I have to say I've found this...
5
by: Velvet | last post by:
Can someone tell me to what process I need to attach to be able to step through my classic ASP code in VS.net 2003. I'm working on an XP box with IIS installed. I also have VS.net 2005 (The...
6
by: KevinGPO | last post by:
I am currently developing a website in ASP (VBScript) using MS Visual C#.NET IDE. I just create a new "ASP.NET Web Application" and point to my local webserver (IIS) of my website address. Then I...
5
by: phnimx | last post by:
Hi , We have developed a number of plug-in .NET Library Components that we typically deploy with our various applications by installing them into the GAC. Each of the applications contains an...
5
by: =?Utf-8?B?Z2FkeWE=?= | last post by:
I can't get to debug on my local IIS using VStudio.net 2005 Prof. I can on the development server. I get the msg 'the server does not support debugging for asp.net...' I have done the following...
2
jwwicks
by: jwwicks | last post by:
C/C++ Programs and Debugging in Linux This tutorial will give you a basic idea how to debug a program in Linux using GDB. As you are aware Visual Studio doesn’t run on Linux so you have to use...
4
by: =?Utf-8?B?TWlrZSBHYWxl?= | last post by:
VS 2008 initially didn't debug classic ASP. SP1 fixes this in some ways. You can debug if you select the debug option to "Start Without Debugging, then either attach the debugger manually or...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.