]> granicus.if.org Git - php/commitdiff
Move undefined constant error into get_constant_ex
authorNikita Popov <nikita.ppv@gmail.com>
Fri, 10 Jan 2020 10:47:35 +0000 (11:47 +0100)
committerNikita Popov <nikita.ppv@gmail.com>
Fri, 10 Jan 2020 10:48:10 +0000 (11:48 +0100)
All the other error conditions are already handled in there, so
this one should be as well.

Zend/zend_ast.c
Zend/zend_constants.c
Zend/zend_execute.h
Zend/zend_execute_API.c

index a27ca9be0a756a69aa3518fb1c64eee8882e71e6..c88e6658edadf6eb427ff59335c08ba66258119f 100644 (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;
index 3148180a9a5c6219b0cc51e3fe9a56c9f300953d..84e7891aba2507354686cbfd1c487c660e1d984e 100644 (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)
index 70f91ad66fe15adc1bb1515d38e8266866017539..e2782e2127c5634e872999b5ff3219a954d264a5 100644 (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 {
index de6af0e5d518c3ff8abc6008c3952f15e188bd95..a1bae5ea3add4a285378217d399bd809ab14ed92 100644 (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 {