Category: Debugging

2009-07-15

Debugging with FirePHP

by Charles — Categories: Debugging, PHP — Tags: , , , Leave a comment

I just discovered FirePHP today (via a discussion at PHPBuilder.com), a set of PHP classes along with a Firefox add-on which allows you to debug your PHP scripts through the Firebug console (a separate Firefox add-on you’ll also need to install if you haven’t already done so).

Essentially, what it does is allow your PHP server-side scripts to output debug information to your browser via a set of HTTP headers which are then intercepted and displayed by the Firebug console window. This way, instead of doing a var_dump() or print_r() to view a variable or object in the middle of your HTML output (or routing it to a log file on the server), you can view that info separately in the Firebug window.

Here’s a quick example of the most basic usage:

(more…)

2008-06-29

Beginners’ Corner: The Dreaded Blank Page

by Charles — Categories: Beginners' Corner, Debugging — Tags: , , 3 Comments

[2008/07/15: Added this to the "Beginners' Corner" category]

A common problem I see new PHP users running into is having a script output absolutely nothing: the dreaded “blank page” syndrome. This is normally due to a syntax error of some sort generating a fatal parse error. As this error is generated before any of the script is actually executed, none of the file’s output ever gets sent to the browser. If the current PHP environment on the server has display_errors turned off, then not even the error message generated by the parser gets displayed. Additionally, since no PHP commands actually get executed when there is a parse error, turning on display_errors within that script via the ini_set() function will make no difference.

The two usual approaches to debugging such problems are to either search the PHP or web server error logs to look for relevant error messages, or else to turn on display_errors, either globally in the php.ini file or at the directory level via a .htaccess file, assuming you are running under Apache and the necessary Apache settings are in effect to allow this. (A third alternative is to use an editor that has PHP syntax checking built in, such as PHPDesigner.)

If for some reason none of those approaches is practical for your situation, a simple way to have any  parse errors be displayed is to create a tiny wrapper script that includes the offending file:

<?php
ini_set('display_errors', 1);
error_reporting(E_ALL | E_STRICT);
include 'path/to/flawed/file.php';
?>

All you have to do is run this script in your browser, et voilà, your parse errors will now be displayed.

© 2012 PHP Musings All rights reserved - Wallow theme v0.46.4 by ([][]) TwoBeers - Powered by WordPress - Have fun!