@@ -2206,6 +2206,13 @@ static void zend_do_traits_method_binding(zend_class_entry *ce, zend_class_entry
2206
2206
2207
2207
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 ) /* {{{ */
2208
2208
{
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
+ */
2209
2216
size_t i ;
2210
2217
2211
2218
if (colliding_ce == ce ) {
@@ -2216,7 +2223,7 @@ static zend_class_entry* find_first_constant_definition(zend_class_entry *ce, ze
2216
2223
}
2217
2224
}
2218
2225
}
2219
-
2226
+ /* Traits don't have it, then the composing class (or trait) itself has it. */
2220
2227
return colliding_ce ;
2221
2228
}
2222
2229
/* }}} */
@@ -2275,7 +2282,16 @@ static void zend_do_traits_constant_binding(zend_class_entry *ce, zend_class_ent
2275
2282
ce -> ce_flags |= ZEND_ACC_HAS_AST_CONSTANTS ;
2276
2283
}
2277
2284
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
+ */
2278
2293
constant -> ce = ce ;
2294
+
2279
2295
Z_TRY_ADDREF (constant -> value );
2280
2296
constant -> doc_comment = constant -> doc_comment ? zend_string_copy (constant -> doc_comment ) : NULL ;
2281
2297
if (constant -> attributes && (!(GC_FLAGS (constant -> attributes ) & IS_ARRAY_IMMUTABLE ))) {
0 commit comments