Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions Zend/tests/error_reporting/error_reporting_const_expr.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
--TEST--
error_reporting via INI: Konstanten-Ausdruck (E_ERROR | E_CORE_ERROR)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please use English in the test names

--ENV--
PHP_INI_ERROR_REPORTING="E_ERROR | E_CORE_ERROR"
--INI--
error_reporting="${PHP_INI_ERROR_REPORTING}"
--FILE--
<?php
echo "error_reporting: ", error_reporting(), "\n";
echo "E_ERROR | E_CORE_ERROR: ", (E_ERROR | E_CORE_ERROR), "\n";
--EXPECTF--
error_reporting: %d
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you should also test that those two values are the same, I suspect this test would pass on the current master too since it just requires that the results be numbers

E_ERROR | E_CORE_ERROR: %d
38 changes: 36 additions & 2 deletions Zend/zend.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,43 @@ static ZEND_INI_MH(OnUpdateErrorReporting) /* {{{ */
{
if (!new_value) {
EG(error_reporting) = E_ALL;
} else {
EG(error_reporting) = atoi(ZSTR_VAL(new_value));
return SUCCESS;
}

char *endptr = NULL;
long val = strtol(ZSTR_VAL(new_value), &endptr, 0);
if (endptr && *endptr == '\0') {
EG(error_reporting) = val;
return SUCCESS;
}

zval result;
zend_string *expr_code = zend_strpprintf(0, "%s;", ZSTR_VAL(new_value));
zend_ast *ast = NULL;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggest declaring this variable as part of its definition lower down

zend_ast *ast = zend_compile_string_to_ast(expr_code, &ast_arena, ZSTR_EMPTY_ALLOC());

zend_arena *ast_arena = NULL;
int success = 0;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

variable appears unused

Suggested change
int success = 0;


ast = zend_compile_string_to_ast(expr_code, &ast_arena, ZSTR_EMPTY_ALLOC());
zend_string_release(expr_code);
if (ast) {
zend_ast_list *stmt_list = zend_ast_get_list(ast);
zend_ast *expr_ast = (stmt_list && stmt_list->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;
}
/* }}} */
Expand Down
Loading