Is there a way that I enforce that PHP reports err

2019-08-07 09:14发布

I made a huge mistake by mixing result with results and it took me around 4 hours to finally find the bug.

So here is the question, in PHP, is it possible that I can enforce PHP to report errors if I use an undefined/uninitialized variable.

thank you

5条回答
兄弟一词,经得起流年.
2楼-- · 2019-08-07 09:35

it already does report an error. something like this:

"Notice:  Undefined variable: a in C:\wamp\www\testcenter\index.PHP on line 40"

maybe you didn't go specific enough. but you should try error_reporting(-1); as as if enforces the php to show some recomendations. a piece from the php manual about E_STRICT errors:

Enable to have PHP suggest changes to your code which will ensure the best interoperability and forward compatibility of your code.

just remember that error_reporting(-1); shows more errors than error_reporting(E_ALL); because E_STRICT errors are not included in the E_ALL constraint.

查看更多
淡お忘
3楼-- · 2019-08-07 09:46

Set error reporting to E_ALL and ensure that display_errors in php.ini is on.

php.ini

display_errors = On

PHP code

// If you cannot access the php.ini file
// you can do this within your PHP code instead
@ini_set('display_errors' '1');
error_reporting(E_ALL);

The default setting you have right now probably excludes notices, the kind of errors PHP raises on uninitialized variables, which could be something like this:

error_reporting(E_ALL & ~E_NOTICE);
查看更多
Summer. ? 凉城
4楼-- · 2019-08-07 09:52

In a development environment I prefer using error_reporting(-1). Which reports all PHP errors.

查看更多
看我几分像从前
5楼-- · 2019-08-07 09:54

yes, use error_reporting() and set it to E_ALL, like this:

 error_reporting(E_ALL);
查看更多
ら.Afraid
6楼-- · 2019-08-07 09:57

Set error reporting to report all errors. Either in php.ini or at runtime using error_reporting(E_ALL)

查看更多
登录 后发表回答