0

Possible Duplicate:
How to get useful error messages in PHP?

Im currently learning php and at the same time a bit of ruby on rails, one of the thing ive noticed about ruby on rails that i really like is when theres an error on page, it will display you an error page pointing you in the direction of what is wrong.. like the image bellow

ruby on rails error

But when i get an error in php i just get a blank page, which means i have to read through each line of code to try and find what went wrong, as ive just started most of my errors tend to be little syntax problems, which are relatively easy to fix, but relatively hard to find if you've missed a ; off the end of a line.

Is there a line that i could put into my <head> during development to show me these errors ? Somthing like <?php show_errors ?>

Or is there an alternative, at the moment im using sublime text 2, Mamp and Firefox to work in. Is there a setting in any of those that i can turn on to allow me to see errors, either code validation in sublime text 2 or a setting in mamp or firefox that will show me an error page instead of a blank one ?

If i was to use a framework do any of them have built in error alerts ?

Community
  • 1
  • 1
sam
  • 9,486
  • 36
  • 109
  • 160
  • does XDebug make your PHP less 'Vanilla' ? Because it is a very useful extension, and it will print more detailed error messages than plain PHP. – SirDarius Jan 20 '13 at 14:30
  • 1
    Enable display_errors in PHP, `error_reporting(E_ALL); ini_set('display_errors', 1);` (or set both of these in php.ini), then install the [xdebug extension](http://xdebug.org) to get nicer formatting on the errors. – Michael Berkowski Jan 20 '13 at 14:32

1 Answers1

2

To resolve your blank page issue, you'll have to reconfigure PHP

display_errors = on
display_startup_errors = on

It is important to set them outside your script (i.e. not with ini_set()), otherwise parse errors will still result in a blank page. See documentation for details.

Then, on top of your script, assure that every kind of error gets shown:

error_reporting(-1)

For nicer error messages you could install XDebug (it is a common extension, not a framework and does not affect your code in any way).

Fabian Schmengler
  • 24,155
  • 9
  • 79
  • 111