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

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

报告相同问题?

悬赏问题

  • ¥15 用hfss做微带贴片阵列天线的时候分析设置有问题
  • ¥50 我撰写的python爬虫爬不了 要爬的网址有反爬机制
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥120 计算机网络的新校区组网设计
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等