PHP error debugging

A place to discuss the implementation and style of computer programs.

Moderators: phlip, Moderators General, Prelates

v1nsai
Posts: 332
Joined: Tue Feb 03, 2009 4:15 am UTC
Location: Florida

PHP error debugging

Postby v1nsai » Tue Nov 30, 2010 12:42 am UTC

Since PHP is server side instead of client side, I know debugging it is a completely different animal than javascript, and I've been researching around but all I have found are things like FirePHP (webug in Chrome) and PHP Console and both of them seem to require putting special method calls to output your own custom error messages.

I feel like I'm missing something, because it seems silly that php doesn't output it's own error messages. If I'm understanding this correctly, if I misspell a function call and try to call prinnt_r() instead of print_r(), there is no error message unless I do something like

Code: Select all

<?phprequire_once('FirePHPCore/FirePHP.class.PHP');
$firephp = FirePHP::getInstance(true);
$array = explode("Herp with a little derp");
if( prinnt_r($array, true) != null)
    $firephp -> error("Go ahead and panic");
?>

Seems like it would require a helluva lot of extra code just to log and debug simple errors. Or are PHP developers so badass you simply don't allow simple errors :mrgreen:
C:\dos
C:\dos.run
run dos.run

User avatar
Area Man
Posts: 256
Joined: Thu Dec 25, 2008 8:08 pm UTC
Location: Local

Re: PHP error debugging

Postby Area Man » Tue Nov 30, 2010 1:32 am UTC

You can set display_errors on to show up in the browser. It will also write an error log.

http://www.php.net/manual/en/errorfunc. ... ration.php
Bisquick boxes are a dead medium.

v1nsai
Posts: 332
Joined: Tue Feb 03, 2009 4:15 am UTC
Location: Florida

Re: PHP error debugging

Postby v1nsai » Tue Nov 30, 2010 2:22 am UTC

Awesome, that makes sense. NOW...is there any way to access php errors from the Chrome Developer Tools?
C:\dos
C:\dos.run
run dos.run

keeperofdakeys
Posts: 658
Joined: Wed Oct 01, 2008 6:04 am UTC

Re: PHP error debugging

Postby keeperofdakeys » Wed Dec 01, 2010 3:25 pm UTC

v1nsai wrote:Awesome, that makes sense. NOW...is there any way to access php errors from the Chrome Developer Tools?

No, becuase the php parser and the web browser are totally disconnected. The web server only talks to the php parser when needed anyway.
I'm pretty sure php has an error log somewhere though.

Also, the reason that php shouldn't show errors by default is that:
1. They don't look very professional.
2. They could give the bad guys extra clues into breaking into your website.

v1nsai
Posts: 332
Joined: Tue Feb 03, 2009 4:15 am UTC
Location: Florida

Re: PHP error debugging

Postby v1nsai » Thu Dec 02, 2010 4:02 am UTC

Yea that's true, I'm gonna have it dump to a file and write myself a script to display the file and refresh it every few seconds. It's weird being so far away from my own code, even though I'm running the PHP parser on localhost
C:\dos
C:\dos.run
run dos.run

User avatar
Robert'); DROP TABLE *;
Posts: 730
Joined: Mon Sep 08, 2008 6:46 pm UTC
Location: in ur fieldz

Re: PHP error debugging

Postby Robert'); DROP TABLE *; » Thu Dec 02, 2010 8:56 pm UTC

Have you tried error_reporting( E_ALL )? That'll make PHP return a page listing any errors. (Obviously, not a good idea to use in production code)
...And that is how we know the Earth to be banana-shaped.

User avatar
Emu*
Posts: 689
Joined: Mon Apr 28, 2008 9:47 am UTC
Location: Cardiff, UK
Contact:

Re: PHP error debugging

Postby Emu* » Fri Dec 03, 2010 11:19 am UTC

(Obviously not a good idea to develop on the live server)
Cosmologicon wrote:Emu* implemented a naive east-first strategy and ran it for an hour, producing results that rivaled many sophisticated strategies, visiting 614 cells. For this, Emu* is awarded Best Deterministic Algorithm!

Filius Nullius
Posts: 72
Joined: Sat Apr 05, 2008 12:24 am UTC

Re: PHP error debugging

Postby Filius Nullius » Tue Dec 14, 2010 8:41 am UTC

You can use xdebug along with netbeans.

archeleus
Posts: 240
Joined: Wed Sep 29, 2010 1:49 pm UTC
Location: Valenvaryon
Contact:

Re: PHP error debugging

Postby archeleus » Thu Dec 16, 2010 2:22 am UTC

Eclipse with PDT and $watch </path/to/log/file> will do in most cases.
I write a blog rant here.

User avatar
Red Rule
Posts: 23
Joined: Thu Apr 29, 2010 11:24 am UTC

Re: PHP error debugging

Postby Red Rule » Sun Dec 19, 2010 8:58 pm UTC

I may be missing the point here, but why not run it from the CLI?
just type (on linux atleast) php PathToYourFile and it will output where it finds any errors.
(e.g. "Line 15: expecting ; " or something along those lines)

you could even make a little script to run it from your browser as well as CLI.
Or better yet, have it run from the browser when there are no errors, else show the CLI. (Which, come to think of it, I'm going to write now...)
"I gotta have a little bit of Orange juice
I gotta have.. my.. Orange juice!
I gotta have.. my.. Orange juice!
Juice juice juice juice juice juice juice juice
"

~Richard Feynman

keeperofdakeys
Posts: 658
Joined: Wed Oct 01, 2008 6:04 am UTC

Re: PHP error debugging

Postby keeperofdakeys » Sun Dec 19, 2010 10:04 pm UTC

Red Rule wrote:I may be missing the point here, but why not run it from the CLI?
just type (on linux atleast) php PathToYourFile and it will output where it finds any errors.
(e.g. "Line 15: expecting ; " or something along those lines)

you could even make a little script to run it from your browser as well as CLI.
Or better yet, have it run from the browser when there are no errors, else show the CLI. (Which, come to think of it, I'm going to write now...)

Although this gets syntax errors, you can't really use things like get, post or cookies here, which means you can't test runtime errors on most websites.


Return to “Coding”

Who is online

Users browsing this forum: No registered users and 12 guests