views:

244

answers:

4

I'm using TextWrangler to edit PHP code. I often run into the problem that the code just displays as a blank page in my development environment. Is there a good way to further target which place I should look in my code for the problem?

Right now I'm just manually running through every line any time I run into this, but I'm guessing there is some sort of solution for this that I haven't been able to find the name for..

+2  A: 

You should make sure your development php.ini file contains:

display_errors = On
error_reporting  =  E_ALL

or

display_errors = On
error_reporting  =  E_ALL | E_STRICT

Even with these on, sometimes an out-of-memory error can cause a blank page.

Greg
A: 

Set php.ini error_reporting to E_ALL

display_error = On
error_reporting = E_ALL

You can do this in your code also.

error_reporting(E_ALL);

or

ini_set('error_reporting', E_ALL);

You can read more about error reporting here.

Ólafur Waage
A: 

In the development process you should always set the error reporting to the highest level (E_ALL/E_STRICT) to get every error reported.

Gumbo
A: 

I've been struggling with this for a while (students learn PHP in some of my classes) because I tried using

ini_set('display_errors', 1);

as suggested (e.g. Ullman's PHPv6 and MySQL 5), but placing it in your code did not catch any parse errors. Instead I continued to see blank pages.

A comment in the PHP Manual webpages has given me a clue as to why setting

display_errors = On

in php.ini is not quite the same as adding

ini_set('display_errors', 1);

at the top of your php script. It seems that PHP has a 2-phase operation and parses the script file completely before it starts to execute any of it. If parsing fails because of a missing ";" or ")", then the

ini_set('display_errors', 1);

gets parsed but never executed and so the parse error is not reported. The same comment offers a way to report parse errors if you do not have the means to change the php.ini settings.

cjakeman