Skip to content

Commit b1226c8

Browse files
committed
Add comments
1 parent a6a5f4b commit b1226c8

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

Zend/zend_inheritance.c

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2206,6 +2206,13 @@ static void zend_do_traits_method_binding(zend_class_entry *ce, zend_class_entry
22062206

22072207
static zend_class_entry* find_first_constant_definition(zend_class_entry *ce, zend_class_entry **traits, size_t current_trait, zend_string *constant_name, zend_class_entry *colliding_ce) /* {{{ */
22082208
{
2209+
/* This function is used to show the place of the existing conflicting
2210+
* definition in error messages when conflicts occur. Since trait constants
2211+
* are flattened into the constants table of the composing class, and thus
2212+
* we lose information about which constant was defined in which trait, a
2213+
* process like this is needed to find the location of the first definition
2214+
* of the constant from traits.
2215+
*/
22092216
size_t i;
22102217

22112218
if (colliding_ce == ce) {
@@ -2216,7 +2223,7 @@ static zend_class_entry* find_first_constant_definition(zend_class_entry *ce, ze
22162223
}
22172224
}
22182225
}
2219-
2226+
/* Traits don't have it, then the composing class (or trait) itself has it. */
22202227
return colliding_ce;
22212228
}
22222229
/* }}} */
@@ -2275,7 +2282,16 @@ static void zend_do_traits_constant_binding(zend_class_entry *ce, zend_class_ent
22752282
ce->ce_flags |= ZEND_ACC_HAS_AST_CONSTANTS;
22762283
}
22772284

2285+
/* Unlike interface implementations and class inheritances,
2286+
* access control of the trait constants is done by the scope
2287+
* of the composing class. So let's replace the ce here.
2288+
* And the result of this, the values, doc comments, and
2289+
* attributes associated with the copied zend_class_constant
2290+
* are destroyed at the time of destroying the class entry of
2291+
* the composing class.
2292+
*/
22782293
constant->ce = ce;
2294+
22792295
Z_TRY_ADDREF(constant->value);
22802296
constant->doc_comment = constant->doc_comment ? zend_string_copy(constant->doc_comment) : NULL;
22812297
if (constant->attributes && (!(GC_FLAGS(constant->attributes) & IS_ARRAY_IMMUTABLE))) {

0 commit comments

Comments
 (0)