Skip to content

Commit 0a2f6c5

Browse files
committed
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.
1 parent b79efec commit 0a2f6c5

File tree

4 files changed

+16
-28
lines changed

4 files changed

+16
-28
lines changed

Zend/zend_ast.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -531,8 +531,7 @@ ZEND_API int ZEND_FASTCALL zend_ast_evaluate(zval *result, zend_ast *ast, zend_c
531531

532532
if (UNEXPECTED(zv == NULL)) {
533533
ZVAL_UNDEF(result);
534-
ret = zend_use_undefined_constant(name, ast->attr, result);
535-
break;
534+
return FAILURE;
536535
}
537536
ZVAL_COPY_OR_DUP(result, zv);
538537
break;

Zend/zend_constants.c

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,7 @@ ZEND_API zval *zend_get_constant_ex(zend_string *cname, zend_class_entry *scope,
402402
}
403403

404404
/* non-class constant */
405+
zval *value;
405406
if ((colon = zend_memrchr(name, '\\', name_len)) != NULL) {
406407
/* compound constant name */
407408
int prefix_len = colon - name;
@@ -426,19 +427,24 @@ ZEND_API zval *zend_get_constant_ex(zend_string *cname, zend_class_entry *scope,
426427
return &c->value;
427428
}
428429

429-
if (!(flags & IS_CONSTANT_UNQUALIFIED_IN_NAMESPACE)) {
430-
return NULL;
430+
if (flags & IS_CONSTANT_UNQUALIFIED_IN_NAMESPACE) {
431+
/* name requires runtime resolution, need to check non-namespaced name */
432+
value = zend_get_constant_str(constant_name, const_name_len);
433+
} else {
434+
value = NULL;
431435
}
432-
433-
/* name requires runtime resolution, need to check non-namespaced name */
434-
return zend_get_constant_str(constant_name, const_name_len);
435436
} else {
436437
if (cname) {
437-
return zend_get_constant(cname);
438+
value = zend_get_constant(cname);
438439
} else {
439-
return zend_get_constant_str(name, name_len);
440+
value = zend_get_constant_str(name, name_len);
440441
}
441442
}
443+
444+
if (!value && !(flags & ZEND_FETCH_CLASS_SILENT)) {
445+
zend_throw_error(NULL, "Undefined constant '%s'", name);
446+
}
447+
return value;
442448
}
443449

444450
static void* zend_hash_add_constant(HashTable *ht, zend_string *key, zend_constant *c)

Zend/zend_execute.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,6 @@ static zend_always_inline zval* zend_assign_to_variable(zval *variable_ptr, zval
146146

147147
ZEND_API int zval_update_constant(zval *pp);
148148
ZEND_API int zval_update_constant_ex(zval *pp, zend_class_entry *scope);
149-
ZEND_API ZEND_COLD int zend_use_undefined_constant(zend_string *name, zend_ast_attr attr, zval *result);
150149

151150
/* dedicated Zend executor functions - do not use! */
152151
struct _zend_vm_stack {

Zend/zend_execute_API.c

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -557,22 +557,6 @@ ZEND_API zend_bool zend_is_executing(void) /* {{{ */
557557
}
558558
/* }}} */
559559

560-
ZEND_API ZEND_COLD int zend_use_undefined_constant(zend_string *name, zend_ast_attr attr, zval *result) /* {{{ */
561-
{
562-
char *colon;
563-
564-
if (UNEXPECTED(EG(exception))) {
565-
return FAILURE;
566-
} else if ((colon = (char*)zend_memrchr(ZSTR_VAL(name), ':', ZSTR_LEN(name)))) {
567-
zend_throw_error(NULL, "Undefined class constant '%s'", ZSTR_VAL(name));
568-
return FAILURE;
569-
} else {
570-
zend_throw_error(NULL, "Undefined constant '%s'", ZSTR_VAL(name));
571-
return FAILURE;
572-
}
573-
}
574-
/* }}} */
575-
576560
ZEND_API int zval_update_constant_ex(zval *p, zend_class_entry *scope) /* {{{ */
577561
{
578562
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) /* {{{ */
581565
if (ast->kind == ZEND_AST_CONSTANT) {
582566
zend_string *name = zend_ast_get_constant_name(ast);
583567
zval *zv = zend_get_constant_ex(name, scope, ast->attr);
584-
585568
if (UNEXPECTED(zv == NULL)) {
586-
return zend_use_undefined_constant(name, ast->attr, p);
569+
return FAILURE;
587570
}
571+
588572
zval_ptr_dtor_nogc(p);
589573
ZVAL_COPY_OR_DUP(p, zv);
590574
} else {

0 commit comments

Comments
 (0)