douqiao1997 2013-01-20 14:28
浏览 23
已采纳

让vanilla php显示错误而不是空白页,就像ROR一样[重复]

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 ?

  • 写回答

1条回答 默认 最新

  • doumaojin4008 2013-01-20 14:45
    关注

    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).

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?