views:

105

answers:

5

I can't change the php.ini for some reason,

how can I do it in code level?

+3  A: 

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:

Example from Manual:

// Report all PHP errors
error_reporting(-1);
Gordon
Isn't `error_reporting(-1);` enough ? Do I also set `display_errors` to `on`?
@user198729 error_reporting just sets what is reported, not if it is displayed.
Gordon
+1  A: 

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

Specifically,

ini_set('display_errors', 'E_ALL');

should work

Slokun
Man, this would work, but your code indeed ridiculous :)
Col. Shrapnel
@Col. Shrapnel What's so ridiculous about it?
Slokun
A: 
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:

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

php_flag display_errors on
php_value error_reporting -1
AlexV
*(tip)* Passing in the value `-1` will show every possible error, even when new levels and constants are added in future PHP versions.
Gordon
I guess because it's bytewise and -1 equals to all flags raised?
AlexV
@Gordon handy tip, thanks
adam
@AlexV because Rasmus said so http://twitter.com/rasmus/status/7448448829 ;) well, actually, it's also at the bottom of the manual page for `error_reporting`.
Gordon
Great, thanks a ton for the wip. will use this from now on!
AlexV
A: 

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)

Daniel Ingraham
A: 

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"

Harold1983-