开发者

Difference between error_reporting() and ini_set('error_reporting')?

When using error_reporting() or ini_set('error_reporting') in my scripts, are there any functionality differences开发者_如何学Python between the two? Is one method preferred over the other?

For what it's worth, I see many frameworks using error_reporting(), but both options appear to be set during runtime only, then reset back to their default in php.ini after script execution.


The only small functional difference seems to be that ini_set returns false when it was unable to change the setting and error_reporting always returns the old error level.


"Two roads leading you to Rome": ini_set('error_reporting', ) overrides the parameter set in the php.ini file. error_reporting() receives level number or level id

error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE);

Both options take effect until the script ends its execution. The next one will use the params defined in the .ini, again.


They are functionally identical, but if you are using an IDE that knows the PHP function names, this is an easy way to make sure you don't accidentally mistype the name of the directive you are tying to set.

From the examples section on PHP's Manual Entry for error_reporting():

// Same as error_reporting(E_ALL);
ini_set('error_reporting', E_ALL);


Also, even though the docs stated that the signature for error_reporting is:

int error_reporting ([ int $level ] )

, it's not exactly correct because you can set a string and read it back with ini_get:

error_reporting('123 hello world');

var_dump(ini_get('error_reporting'));

produces:

string(15) "123 hello world"

So, error_reporting($x) is semantically equivalent to ini_set('error_reporting', $x),

and error_reporting() is semantically equivalent to (int)ini_get('error_reporting').

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜