From 0104a406df2ccef5f1c0f2c7382acee1c74c064d Mon Sep 17 00:00:00 2001 From: Sascha Heilmeier Date: Wed, 24 Sep 2025 08:59:13 +0200 Subject: [PATCH] Zend: Support constant expressions in error_reporting ini/env values Previously, error_reporting could only be set to numeric values via ini or environment variables. This patch extends the OnUpdateErrorReporting handler to parse and evaluate constant expressions (e.g., 'E_ERROR | E_CORE_ERROR') using the AST machinery, matching PHP's runtime behavior. Invalid expressions fallback to E_ALL or 0. --- .../error_reporting_const_expr.phpt | 13 +++++++ Zend/zend.c | 38 ++++++++++++++++++- 2 files changed, 49 insertions(+), 2 deletions(-) create mode 100644 Zend/tests/error_reporting/error_reporting_const_expr.phpt diff --git a/Zend/tests/error_reporting/error_reporting_const_expr.phpt b/Zend/tests/error_reporting/error_reporting_const_expr.phpt new file mode 100644 index 0000000000000..af4081aa15627 --- /dev/null +++ b/Zend/tests/error_reporting/error_reporting_const_expr.phpt @@ -0,0 +1,13 @@ +--TEST-- +error_reporting via INI: Konstanten-Ausdruck (E_ERROR | E_CORE_ERROR) +--ENV-- +PHP_INI_ERROR_REPORTING="E_ERROR | E_CORE_ERROR" +--INI-- +error_reporting="${PHP_INI_ERROR_REPORTING}" +--FILE-- +children > 0) ? stmt_list->child[0] : NULL; + if (expr_ast) { + zend_const_expr_to_zval(&result, &expr_ast, 0); + if (Z_TYPE(result) != IS_LONG && Z_TYPE(result) != IS_UNDEF) { + zval_ptr_dtor(&result); + } else { + EG(error_reporting) = Z_LVAL(result); + zval_ptr_dtor(&result); + zend_ast_destroy(ast); + zend_arena_destroy(ast_arena); + return SUCCESS; + } + } + zend_ast_destroy(ast); + zend_arena_destroy(ast_arena); } + EG(error_reporting) = E_ALL; return SUCCESS; } /* }}} */