1
0
mirror of https://github.com/php/php-src.git synced 2026-03-24 00:02:20 +01:00

Move undefined constant error into get_constant_ex

All the other error conditions are already handled in there, so
this one should be as well.
This commit is contained in:
Nikita Popov
2020-01-10 11:47:35 +01:00
parent b79efec994
commit 0a2f6c5527
4 changed files with 16 additions and 28 deletions

View File

@@ -531,8 +531,7 @@ ZEND_API int ZEND_FASTCALL zend_ast_evaluate(zval *result, zend_ast *ast, zend_c
if (UNEXPECTED(zv == NULL)) {
ZVAL_UNDEF(result);
ret = zend_use_undefined_constant(name, ast->attr, result);
break;
return FAILURE;
}
ZVAL_COPY_OR_DUP(result, zv);
break;

View File

@@ -402,6 +402,7 @@ failure:
}
/* non-class constant */
zval *value;
if ((colon = zend_memrchr(name, '\\', name_len)) != NULL) {
/* compound constant name */
int prefix_len = colon - name;
@@ -426,19 +427,24 @@ failure:
return &c->value;
}
if (!(flags & IS_CONSTANT_UNQUALIFIED_IN_NAMESPACE)) {
return NULL;
if (flags & IS_CONSTANT_UNQUALIFIED_IN_NAMESPACE) {
/* name requires runtime resolution, need to check non-namespaced name */
value = zend_get_constant_str(constant_name, const_name_len);
} else {
value = NULL;
}
/* name requires runtime resolution, need to check non-namespaced name */
return zend_get_constant_str(constant_name, const_name_len);
} else {
if (cname) {
return zend_get_constant(cname);
value = zend_get_constant(cname);
} else {
return zend_get_constant_str(name, name_len);
value = zend_get_constant_str(name, name_len);
}
}
if (!value && !(flags & ZEND_FETCH_CLASS_SILENT)) {
zend_throw_error(NULL, "Undefined constant '%s'", name);
}
return value;
}
static void* zend_hash_add_constant(HashTable *ht, zend_string *key, zend_constant *c)

View File

@@ -146,7 +146,6 @@ static zend_always_inline zval* zend_assign_to_variable(zval *variable_ptr, zval
ZEND_API int zval_update_constant(zval *pp);
ZEND_API int zval_update_constant_ex(zval *pp, zend_class_entry *scope);
ZEND_API ZEND_COLD int zend_use_undefined_constant(zend_string *name, zend_ast_attr attr, zval *result);
/* dedicated Zend executor functions - do not use! */
struct _zend_vm_stack {

View File

@@ -557,22 +557,6 @@ ZEND_API zend_bool zend_is_executing(void) /* {{{ */
}
/* }}} */
ZEND_API ZEND_COLD int zend_use_undefined_constant(zend_string *name, zend_ast_attr attr, zval *result) /* {{{ */
{
char *colon;
if (UNEXPECTED(EG(exception))) {
return FAILURE;
} else if ((colon = (char*)zend_memrchr(ZSTR_VAL(name), ':', ZSTR_LEN(name)))) {
zend_throw_error(NULL, "Undefined class constant '%s'", ZSTR_VAL(name));
return FAILURE;
} else {
zend_throw_error(NULL, "Undefined constant '%s'", ZSTR_VAL(name));
return FAILURE;
}
}
/* }}} */
ZEND_API int zval_update_constant_ex(zval *p, zend_class_entry *scope) /* {{{ */
{
if (Z_TYPE_P(p) == IS_CONSTANT_AST) {
@@ -581,10 +565,10 @@ ZEND_API int zval_update_constant_ex(zval *p, zend_class_entry *scope) /* {{{ */
if (ast->kind == ZEND_AST_CONSTANT) {
zend_string *name = zend_ast_get_constant_name(ast);
zval *zv = zend_get_constant_ex(name, scope, ast->attr);
if (UNEXPECTED(zv == NULL)) {
return zend_use_undefined_constant(name, ast->attr, p);
return FAILURE;
}
zval_ptr_dtor_nogc(p);
ZVAL_COPY_OR_DUP(p, zv);
} else {