@@ -2204,23 +2204,6 @@ static void zend_do_traits_method_binding(zend_class_entry *ce, zend_class_entry
2204
2204
}
2205
2205
/* }}} */
2206
2206
2207
- static zend_class_entry * find_first_property_definition (zend_class_entry * ce , zend_class_entry * * traits , size_t current_trait , zend_string * prop_name , zend_class_entry * colliding_ce ) /* {{{ */
2208
- {
2209
- size_t i ;
2210
-
2211
- if (colliding_ce == ce ) {
2212
- for (i = 0 ; i < current_trait ; i ++ ) {
2213
- if (traits [i ]
2214
- && zend_hash_exists (& traits [i ]-> properties_info , prop_name )) {
2215
- return traits [i ];
2216
- }
2217
- }
2218
- }
2219
-
2220
- return colliding_ce ;
2221
- }
2222
- /* }}} */
2223
-
2224
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 ) /* {{{ */
2225
2208
{
2226
2209
size_t i ;
@@ -2238,9 +2221,8 @@ static zend_class_entry* find_first_constant_definition(zend_class_entry *ce, ze
2238
2221
}
2239
2222
/* }}} */
2240
2223
2241
- static bool do_trait_constant_check (
2242
- zend_class_entry * ce , zend_class_constant * trait_constant , zend_string * name , zend_class_entry * * traits , size_t current_trait
2243
- ) {
2224
+ static bool do_trait_constant_check (zend_class_entry * ce , zend_class_constant * trait_constant , zend_string * name , zend_class_entry * * traits , size_t current_trait ) /* {{{ */
2225
+ {
2244
2226
bool is_compatible = false;
2245
2227
uint32_t flags_mask = ZEND_ACC_PPP_MASK | ZEND_ACC_FINAL ;
2246
2228
@@ -2266,33 +2248,63 @@ static bool do_trait_constant_check(
2266
2248
}
2267
2249
/* }}} */
2268
2250
2269
- static void do_inherit_trait_constant ( zend_string * name , zend_class_constant * c , zend_class_entry * ce , zend_class_entry * * traits , size_t current_trait ) /* {{{ */
2251
+ static void zend_do_traits_constant_binding ( zend_class_entry * ce , zend_class_entry * * traits ) /* {{{ */
2270
2252
{
2271
- if (do_trait_constant_check (ce , c , name , traits , current_trait )) {
2272
- zend_class_constant * ct = NULL ;
2253
+ size_t i ;
2273
2254
2274
- ct = zend_arena_alloc ( & CG ( arena ), sizeof ( zend_class_constant ));
2275
- memcpy ( ct , c , sizeof ( zend_class_constant )) ;
2276
- c = ct ;
2255
+ for ( i = 0 ; i < ce -> num_traits ; i ++ ) {
2256
+ zend_string * constant_name ;
2257
+ zend_class_constant * constant ;
2277
2258
2278
- if (Z_TYPE (c -> value ) == IS_CONSTANT_AST ) {
2279
- ce -> ce_flags &= ~ZEND_ACC_CONSTANTS_UPDATED ;
2280
- ce -> ce_flags |= ZEND_ACC_HAS_AST_CONSTANTS ;
2259
+ if (!traits [i ]) {
2260
+ continue ;
2281
2261
}
2282
2262
2283
- c -> ce = ce ;
2284
- Z_TRY_ADDREF (c -> value );
2285
- c -> doc_comment = c -> doc_comment ? zend_string_copy (c -> doc_comment ) : NULL ;
2286
- if (c -> attributes && (!(GC_FLAGS (c -> attributes ) & IS_ARRAY_IMMUTABLE ))) {
2287
- GC_ADDREF (c -> attributes );
2288
- }
2263
+ ZEND_HASH_MAP_FOREACH_STR_KEY_PTR (& traits [i ]-> constants_table , constant_name , constant ) {
2264
+ if (do_trait_constant_check (ce , constant , constant_name , traits , i )) {
2265
+ zend_class_constant * ct = NULL ;
2289
2266
2290
- zend_hash_update_ptr (& ce -> constants_table , name , c );
2267
+ ct = zend_arena_alloc (& CG (arena ),sizeof (zend_class_constant ));
2268
+ memcpy (ct , constant , sizeof (zend_class_constant ));
2269
+ constant = ct ;
2270
+
2271
+ if (Z_TYPE (constant -> value ) == IS_CONSTANT_AST ) {
2272
+ ce -> ce_flags &= ~ZEND_ACC_CONSTANTS_UPDATED ;
2273
+ ce -> ce_flags |= ZEND_ACC_HAS_AST_CONSTANTS ;
2274
+ }
2275
+
2276
+ constant -> ce = ce ;
2277
+ Z_TRY_ADDREF (constant -> value );
2278
+ constant -> doc_comment = constant -> doc_comment ? zend_string_copy (constant -> doc_comment ) : NULL ;
2279
+ if (constant -> attributes && (!(GC_FLAGS (constant -> attributes ) & IS_ARRAY_IMMUTABLE ))) {
2280
+ GC_ADDREF (constant -> attributes );
2281
+ }
2282
+
2283
+ zend_hash_update_ptr (& ce -> constants_table , constant_name , constant );
2284
+ }
2285
+ } ZEND_HASH_FOREACH_END ();
2286
+ }
2287
+ }
2288
+ /* }}} */
2289
+
2290
+ static zend_class_entry * find_first_property_definition (zend_class_entry * ce , zend_class_entry * * traits , size_t current_trait , zend_string * prop_name , zend_class_entry * colliding_ce ) /* {{{ */
2291
+ {
2292
+ size_t i ;
2293
+
2294
+ if (colliding_ce == ce ) {
2295
+ for (i = 0 ; i < current_trait ; i ++ ) {
2296
+ if (traits [i ]
2297
+ && zend_hash_exists (& traits [i ]-> properties_info , prop_name )) {
2298
+ return traits [i ];
2299
+ }
2300
+ }
2291
2301
}
2302
+
2303
+ return colliding_ce ;
2292
2304
}
2293
2305
/* }}} */
2294
2306
2295
- static void zend_do_traits_property_and_constant_binding (zend_class_entry * ce , zend_class_entry * * traits ) /* {{{ */
2307
+ static void zend_do_traits_property_binding (zend_class_entry * ce , zend_class_entry * * traits ) /* {{{ */
2296
2308
{
2297
2309
size_t i ;
2298
2310
zend_property_info * property_info ;
@@ -2301,8 +2313,6 @@ static void zend_do_traits_property_and_constant_binding(zend_class_entry *ce, z
2301
2313
zend_string * prop_name ;
2302
2314
zval * prop_value ;
2303
2315
zend_string * doc_comment ;
2304
- zend_string * constant_name ;
2305
- zend_class_constant * constant ;
2306
2316
2307
2317
/* In the following steps the properties are inserted into the property table
2308
2318
* for that, a very strict approach is applied:
@@ -2313,10 +2323,6 @@ static void zend_do_traits_property_and_constant_binding(zend_class_entry *ce, z
2313
2323
if (!traits [i ]) {
2314
2324
continue ;
2315
2325
}
2316
- ZEND_HASH_MAP_FOREACH_STR_KEY_PTR (& traits [i ]-> constants_table , constant_name , constant ) {
2317
- do_inherit_trait_constant (constant_name , constant , ce , traits , i );
2318
- } ZEND_HASH_FOREACH_END ();
2319
-
2320
2326
ZEND_HASH_MAP_FOREACH_STR_KEY_PTR (& traits [i ]-> properties_info , prop_name , property_info ) {
2321
2327
uint32_t flags = property_info -> flags ;
2322
2328
@@ -2407,8 +2413,9 @@ static void zend_do_bind_traits(zend_class_entry *ce, zend_class_entry **traits)
2407
2413
efree (exclude_tables );
2408
2414
}
2409
2415
2410
- /* then flatten the properties into it, to, mostly to notify developer about problems */
2411
- zend_do_traits_property_and_constant_binding (ce , traits );
2416
+ /* then flatten the constants and properties into it, to, mostly to notify developer about problems */
2417
+ zend_do_traits_constant_binding (ce , traits );
2418
+ zend_do_traits_property_binding (ce , traits );
2412
2419
}
2413
2420
/* }}} */
2414
2421
0 commit comments