当前位置: 动力学知识库 > 问答 > 编程问答 >

crash - How to intentionally cause a fatal error in PHP script?

问题描述:

I want script to stop being executed at the point of the crash, while not to exhaust the memory or otherwise crash the server.

Any idea how to do that?

网友答案:

I believe this is what you're looking for:

trigger_error("Oops!", E_USER_ERROR);

Docs: http://php.net/manual/en/function.trigger-error.php

E_USER_ERROR is pretty much equal to E_ERROR, which is a fatal runtime error.

网友答案:

Bit late but this a guaranteed natural fatal error:

Call an undefined function, eg:

noSuchFunction();

Or if you want this to be executed when you are in 'test' mode only, then put it into an eval

if($isTestMode==1){
  eval("noSuchFunction();");
}

Edit: With the trigger_error() function the problem is that if you are using set_error_handler() it ceases to be fatal - your error handler will decide what to do with it.

分享给朋友:
您可能感兴趣的文章:
随机阅读: