-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Zend: Support constant expressions in error_reporting ini/env values #19943
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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) | ||
--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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -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; | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. variable appears unused
Suggested change
|
||||
|
||||
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; | ||||
} | ||||
/* }}} */ | ||||
|
There was a problem hiding this comment.
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