Skip to content

Commit a6a5f4b

Browse files
committed
Add comments
1 parent 19a3daf commit a6a5f4b

File tree

2 files changed

+4
-0
lines changed

2 files changed

+4
-0
lines changed

Zend/zend_compile.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1595,6 +1595,9 @@ static bool zend_try_compile_const_expr_resolve_class_name(zval *zv, zend_ast *c
15951595
static bool zend_verify_ct_const_access(zend_class_constant *c, zend_class_entry *scope)
15961596
{
15971597
if (c->ce->ce_flags & ZEND_ACC_TRAIT) {
1598+
/* This condition is only met on directly accessing trait constants,
1599+
* because the ce is replaced to the class entry of the composing class
1600+
* on binding. */
15981601
return 0;
15991602
} else if (ZEND_CLASS_CONST_FLAGS(c) & ZEND_ACC_PUBLIC) {
16001603
return 1;

Zend/zend_constants.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,7 @@ ZEND_API zval *zend_get_class_constant_ex(zend_string *class_name, zend_string *
362362
}
363363

364364
if (UNEXPECTED(ce->ce_flags & ZEND_ACC_TRAIT)) {
365+
/** Prevent accessing trait constants directly on cases like \defined() or \constant(), etc. */
365366
if ((flags & ZEND_FETCH_CLASS_SILENT) == 0) {
366367
zend_throw_error(NULL, "Cannot access trait constant %s::%s directly", ZSTR_VAL(class_name), ZSTR_VAL(constant_name));
367368
}

0 commit comments

Comments
 (0)