开发者

How do I make PHP output all error information programatically?

I 开发者_运维技巧can't change the php.ini for some reason,

how can I do it in code level?


Try

  • ini_set — Sets the value of a configuration option

Example from Manual:

if (!ini_get('display_errors')) {
    ini_set('display_errors', 1);
}

but keep in mind your hosting service might have disabled programmatic setting of ini settings.


Also keep in mind that you have to have error_reporting enabled:

  • error_reporting — Sets which PHP errors are reported

Example from Manual:

// Report all PHP errors
error_reporting(-1);


Use ini_set (http://ca2.php.net/manual/en/function.ini-set.php)

Specifically,

ini_set('display_errors', 'E_ALL');

should work


Runtime configuration of error reporting can be finetuned with a number of functions, listed here: http://www.php.net/manual/en/errorfunc.configuration.php

But most directly related to your question, use error_reporting(E_ALL), and display_errors(1)


error_reporting(-1); //Passing in the value -1 will show every possible error, even when new levels and constants are added in future PHP versions
ini_set('display_errors', 'On');

Doc available there:

  • error_reporting
  • ini_set

Another way (if your server supports it) is with an .htaccess file:

php_flag display_errors on
php_value error_reporting -1


In PHP:

error_reporting(E_ALL | E_STRICT);

From an .htaccess file:

php_value error_reporting 6143 

6143 is the integer value of E_ALL, since apache won't understand "E_ALL"

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜