Reputation: 3823
Can i disallow PHP override php.ini
error_reporting settings? And take this settings only from php.ini
.
php.init file have: error_reporting = E_ERROR|E_PARSE
PHP code have: error_reporting(E_WARNING|E_PARSE);
But this PHP line is in project core and i can't edit it and I don't need E_WARNING
.
Upvotes: 2
Views: 395
Reputation: 21513
edit: just occured to me, you can use php runkit to do this instead of messing with the source code,
option 1:
install runkit ( https://github.com/zenovich/runkit / https://github.com/runkit7/runkit7 ), add runkit.internal_override=1
in php.ini, and run
runkit_function_rename("error_reporting","original_error_reporting");
runkit_function_add("error_reporting",function(int $ignored = NULL){return original_error_reporting();});
before running your intended code (you can also add this code in a file pointed to by the auto_prepend_file
php.ini option to make sure it runs before any other code)
in php-src/Zend/zend_builtin_functions.c find
/* {{{ proto int error_reporting([int new_error_level])
Return the current error_reporting level, and if an argument was passed - change to the new level */
ZEND_FUNCTION(error_reporting)
then right below that find
if (ZEND_NUM_ARGS() != 0) {
replace it with
if (0) {
then recompile PHP, and voila, error_reporting arguments are ignored :)
in git revision ab8094c666048b747481df0b9da94e08cadc4160 , which is 7.3.0-dev (slightly after 7.3.0-beta1), it is on line 736, see https://github.com/php/php-src/blob/ab8094c666048b747481df0b9da94e08cadc4160/Zend/zend_builtin_functions.c#L736
Upvotes: 0
Reputation: 75636
Can i disallow PHP override php.ini error_reporting settings?
You can disallow use of error_reporting()
function in your code with use of disable_functions configuration directive. The downside is that you cannot have
disable_functions = error_reporting
set per vhost (i.e. via php_admin_value
) but it must be set in main php.ini
which may be problematic in some configurations.
Also I believe that your question exposed different problem and you are not fixing it here, but rather working around.
Upvotes: 1