[英]Can I really do nothing with fatal parse errors?
Beginner question: I have done around 30 hours trying to sort out an error handler, essential as I am not a great programmer. 初学者问题:我已经花了大约30个小时来尝试找出错误处理程序,这对我不是一个很好的程序员来说非常重要。 I am 95% sure I can't do anything about fatal-fatal errors but I am still 5% hopeful.
我有95%的信心对致命致命错误无能为力,但我仍然有5%的希望。
My error handler was working well sending out emails and text messages when it encounters problems but then I got an empty page with just: 我的错误处理程序在遇到问题时可以很好地发送电子邮件和文本消息,但是随后我得到了一个空页面,上面只有:
Fatal error: Cannot use try without catch or finally
in /directory/ etc ...filename.php on line 999
(I had accidentally deleted the catch block.) The question: Someone somewhere mentioned htaccess 500
pages. (我不小心删除了catch块。) 问题:某处有人提到
htaccess 500
页。
I did not understand what was described when I read it. 当我阅读它时,我不明白所描述的内容。 I have done almost nothing with
htaccess
up to now. 到目前为止,我对
htaccess
几乎一无所获。
Is there a way to trip some sort of static page? 有没有办法解开某种静态页面? (I am 95% sure I can do nothing but I am stuck and still have a 5% hope and this is really important for me.) I am still running PHP 5.6 but do not want to upgrade to 7 yet.
(我有95%的信心我什么也做不了,但是我被困住了,但仍然有5%的希望,这对我来说真的很重要。)我仍然在运行PHP 5.6,但不想升级到7。 Catching these errors is far more important for me than the warnings, notices, deprecateds etc that I can catch.
对于我来说,捕捉这些错误比我可以捕获的警告,通知,不推荐使用的东西重要得多。
I saw that question and used some of the techniques there BUT it is 11 years old, huge, partly outdated and does NOT primarily address the problem I now want to solve. 我看到了这个问题,并使用了其中的一些技术,但是它已经11年了,巨大,部分过时,并且不能主要解决我现在要解决的问题。
I have no problem dealing with "fatal errors" such as calling a non existent function. 我可以处理“致命错误”,例如调用不存在的函数。 My problem is about errors found when the script is parsed and are "unrecoverable".
我的问题是解析脚本时发现的错误,并且这些错误是“不可恢复的”。 In my case a missing
catch
when a try
is present. 在我的情况下,
try
时丢失了一个catch
。
The other answer, answers this in parts but not in ways that I can seem to use. 另一个答案是部分回答此问题,但并非以我似乎可以使用的方式回答。 I think there maybe a way of forcing a 500 error rather perversely by stopping error display which I will investigate soon/tomorrow.
我认为也许有一种方法可以通过停止错误显示来迫使500错误而不正确地显示,我将在明天/明天进行调查。 I would be grateful for 24 hours to check.
我将不胜感激24小时检查。 I am quite happy for someone more knowledgeable to put up a better question/answer and useful info could be culled from that thread but, frankly it is a mess unsurprisingly after 11 years.
对于一个知识渊博的人提出更好的问题/答案,有用的信息可以从该线索中剔除,我感到非常高兴,但是坦率地说,经过11年,这真是一团糟。
Switch display_errors
to off and you have a 500 error. 将
display_errors
切换为off,您将遇到500错误。 Sadly I cannot get an .htaccess
redirect to work (404 works fine). 可悲的是,我无法使
.htaccess
重定向正常工作(404正常)。 If you are good with .htaccess
hopefully you will have some joy. 如果您对
.htaccess
满意,那么希望您会感到高兴。
In some discussions there is talk of some 500 errors being "CORE" errors and REALLY unrecoverable even by .htaccess
. 在一些讨论中,有人说约有500个错误是“ CORE”错误,即使
.htaccess
无法恢复。 My logs are very sparse and I cannot see any useful indication if this is the case for the catch
when a try
is present error. 我的日志非常稀疏,如果出现
try
错误,是否可以catch
,我看不到任何有用的指示。
(With a big thank you to @Dharman (if it works)). (非常感谢@Dharman(如果可以的话))。 PS Will tidy this up when/if I get to the end of this.)
PS将整理这个,当/如果我结束了。)
I don't think PHP can do anything with parse errors (or other errors during the compilation phase), but you should be able to configure your web server to display an error page of your choosing. 我认为PHP不能对解析错误(或编译阶段的其他错误)做任何事情,但是您应该能够配置Web服务器以显示您选择的错误页面。
You don't say what web server you are using, but for example with Apache these are the Custom Error Response settings. 您没有说要使用什么Web服务器,但是例如对于Apache,这些是“ 自定义错误响应”设置。 Your errors will be HTTP 500 errors.
您的错误将是HTTP 500错误。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.