Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

error_reporting not work correctly to show fatal errors

Tags:

php

i have a page simply like this:

error_reporting(-1);
require('test.txt');

i know that test.txt not exists .i want to try error_reporting() function. in this case that we pass number -1 to function all error reported correctly like this:

Warning: require(test.txt) [function.require]: failed to open stream: No such file or directory in C:\wamp\www\PHP_Class\session_5\errors.php on line 11
Fatal error: require() [function.require]: Failed opening required 'test.txt' (include_path='.;C:\php\pear') in C:\wamp\www\PHP_Class\session_5\errors.php on line 11  

and when we pass number 2 to function like error_reporting(2) only E_WARNING error reported and this is correct too:

Warning: require(test.txt) [function.require]: failed to open stream: No such file or directory in C:\wamp\www\PHP_Class\session_5\errors.php on line 11  

but when i pass number 1 to function like error_reporting(1) for report E_ERROR errors only , no error display. what is problem? please tell me

like image 877
A.B.Developer Avatar asked Jun 28 '26 00:06

A.B.Developer


2 Answers

I think require doesn't throw an E_ERROR but an E_COMPILE_ERROR.
So please try it with error_reporting(E_COMPILE_ERROR);

like image 192
dan-lee Avatar answered Jun 29 '26 12:06

dan-lee


how about this

error_reporting (E_ALL & ~E_WARNING & ~E_NOTICE & ~E_DEPRECATED) ;

this should give you all the errors you require

UPDATE

chk this url

http://www.php.net/manual/en/function.require.php

it says

include except upon failure it will also produce a fatal E_COMPILE_ERROR level error.

so this code will always give the compile error.... And the config above will be best suited for you production env..

like image 38
Sandeep Rajoria Avatar answered Jun 29 '26 12:06

Sandeep Rajoria