Stop script execution upon notice/warning

后端 未结 6 998
迷失自我
迷失自我 2020-11-30 00:45

Is it possible to have PHP stop execution upon a notice/warning, globally?

We run a development server with a lot of sites on, but want to force our developers to fi

6条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-11-30 01:09

    As of PHP 5.3.0:

    set_error_handler(
        function(int $nSeverity, string $strMessage, string $strFilePath, int $nLineNumber){
            if(error_reporting()!==0) // Not error suppression operator @
                throw new \ErrorException($strMessage, /*nExceptionCode*/ 0, $nSeverity, $strFilePath, $nLineNumber);
        },
        /*E_ALL*/ -1
    );
    

提交回复
热议问题