Is there a way that I enforce that PHP reports err

2019-08-07 08:54发布

问题:

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

回答1:

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);


回答2:

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



回答3:

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

 error_reporting(E_ALL);


回答4:

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



回答5:

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.