Beginners’ Corner: The Dreaded Blank Page
June 29, 2008 Beginners' Corner, Debugging 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.
