开发者

PHP error display removing all other content

开发者 https://www.devze.com 2022-12-08 22:49 出处:网络
On a development server here, a setting has been changed which makes any PHP error (of any level) only output the error message and nothing else. To demonstrate what I mean, here\'s a script to reprod

On a development server here, a setting has been changed which makes any PHP error (of any level) only output the error message and nothing else. To demonstrate what I mean, here's a script to reproduce the error:

<?php
$array = array('a');
echo "Hello world";
echo $array[1];
echo $array[2];
echo "Goodbye world";
?>

What I'd expect from this is "Hello world", then two PHP Notices saying that there was an undefined offset in the array, and then "Goodbye world". What I actually see is this:

PHP Notice:  Undefined offset:  1 in /path/to/myfile.php on line 4
PHP Notice:  Undefined offset:  2 in /path/to/myfile.php on line 5

...and nothing else. (Also note that it's in plain text like that, not HTML). Of course, I could set error_reporting(0), but then I don't see any of the errors.

Does anyone know what PHP setting wou开发者_StackOverflow中文版ld control this?


My guess is that output buffering has been turned on. Try:

<?php
$array = array('a');
echo "Hello world";
ob_flush();
echo $array[1];
echo $array[2];
echo "Goodbye world";
?>


You need to turn off the warnings, and just get the fatal errors. This should do that:

error_reporting(E_ERROR | E_WARNING | E_PARSE);

or this:

error_reporting(E_ERROR | E_PARSE);

the error reporting method is taking an integer here, and the pipe character is bitwise or-ing their underlying integer values together to achieve the final integer passed to the function.

http://74.125.155.132/search?q=cache:QvgitR0nX34J:php.net/manual/en/function.error-reporting.php+php+fatal+error+reporting&cd=1&hl=en&ct=clnk&gl=us

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号