@@ -2135,23 +2135,6 @@ static void zend_do_traits_method_binding(zend_class_entry *ce, zend_class_entry
2135
2135
}
2136
2136
/* }}} */
2137
2137
2138
- 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 ) /* {{{ */
2139
- {
2140
- size_t i ;
2141
-
2142
- if (colliding_ce == ce ) {
2143
- for (i = 0 ; i < current_trait ; i ++ ) {
2144
- if (traits [i ]
2145
- && zend_hash_exists (& traits [i ]-> properties_info , prop_name )) {
2146
- return traits [i ];
2147
- }
2148
- }
2149
- }
2150
-
2151
- return colliding_ce ;
2152
- }
2153
- /* }}} */
2154
-
2155
2138
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 ) /* {{{ */
2156
2139
{
2157
2140
size_t i ;
@@ -2169,9 +2152,8 @@ static zend_class_entry* find_first_constant_definition(zend_class_entry *ce, ze
2169
2152
}
2170
2153
/* }}} */
2171
2154
2172
- static bool do_trait_constant_check (
2173
- zend_class_entry * ce , zend_class_constant * trait_constant , zend_string * name , zend_class_entry * * traits , size_t current_trait
2174
- ) {
2155
+ 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 ) /* {{{ */
2156
+ {
2175
2157
bool is_compatible = false;
2176
2158
uint32_t flags_mask = ZEND_ACC_PPP_MASK | ZEND_ACC_FINAL ;
2177
2159
@@ -2197,33 +2179,63 @@ static bool do_trait_constant_check(
2197
2179
}
2198
2180
/* }}} */
2199
2181
2200
- 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 ) /* {{{ */
2182
+ static void zend_do_traits_constant_binding ( zend_class_entry * ce , zend_class_entry * * traits ) /* {{{ */
2201
2183
{
2202
- if (do_trait_constant_check (ce , c , name , traits , current_trait )) {
2203
- zend_class_constant * ct = NULL ;
2184
+ size_t i ;
2204
2185
2205
- ct = zend_arena_alloc ( & CG ( arena ), sizeof ( zend_class_constant ));
2206
- memcpy ( ct , c , sizeof ( zend_class_constant )) ;
2207
- c = ct ;
2186
+ for ( i = 0 ; i < ce -> num_traits ; i ++ ) {
2187
+ zend_string * constant_name ;
2188
+ zend_class_constant * constant ;
2208
2189
2209
- if (Z_TYPE (c -> value ) == IS_CONSTANT_AST ) {
2210
- ce -> ce_flags &= ~ZEND_ACC_CONSTANTS_UPDATED ;
2211
- ce -> ce_flags |= ZEND_ACC_HAS_AST_CONSTANTS ;
2190
+ if (!traits [i ]) {
2191
+ continue ;
2212
2192
}
2213
2193
2214
- c -> ce = ce ;
2215
- Z_TRY_ADDREF (c -> value );
2216
- c -> doc_comment = c -> doc_comment ? zend_string_copy (c -> doc_comment ) : NULL ;
2217
- if (c -> attributes && (!(GC_FLAGS (c -> attributes ) & IS_ARRAY_IMMUTABLE ))) {
2218
- GC_ADDREF (c -> attributes );
2219
- }
2194
+ ZEND_HASH_MAP_FOREACH_STR_KEY_PTR (& traits [i ]-> constants_table , constant_name , constant ) {
2195
+ if (do_trait_constant_check (ce , constant , constant_name , traits , i )) {
2196
+ zend_class_constant * ct = NULL ;
2220
2197
2221
- zend_hash_update_ptr (& ce -> constants_table , name , c );
2198
+ ct = zend_arena_alloc (& CG (arena ),sizeof (zend_class_constant ));
2199
+ memcpy (ct , constant , sizeof (zend_class_constant ));
2200
+ constant = ct ;
2201
+
2202
+ if (Z_TYPE (constant -> value ) == IS_CONSTANT_AST ) {
2203
+ ce -> ce_flags &= ~ZEND_ACC_CONSTANTS_UPDATED ;
2204
+ ce -> ce_flags |= ZEND_ACC_HAS_AST_CONSTANTS ;
2205
+ }
2206
+
2207
+ constant -> ce = ce ;
2208
+ Z_TRY_ADDREF (constant -> value );
2209
+ constant -> doc_comment = constant -> doc_comment ? zend_string_copy (constant -> doc_comment ) : NULL ;
2210
+ if (constant -> attributes && (!(GC_FLAGS (constant -> attributes ) & IS_ARRAY_IMMUTABLE ))) {
2211
+ GC_ADDREF (constant -> attributes );
2212
+ }
2213
+
2214
+ zend_hash_update_ptr (& ce -> constants_table , constant_name , constant );
2215
+ }
2216
+ } ZEND_HASH_FOREACH_END ();
2217
+ }
2218
+ }
2219
+ /* }}} */
2220
+
2221
+ 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 ) /* {{{ */
2222
+ {
2223
+ size_t i ;
2224
+
2225
+ if (colliding_ce == ce ) {
2226
+ for (i = 0 ; i < current_trait ; i ++ ) {
2227
+ if (traits [i ]
2228
+ && zend_hash_exists (& traits [i ]-> properties_info , prop_name )) {
2229
+ return traits [i ];
2230
+ }
2231
+ }
2222
2232
}
2233
+
2234
+ return colliding_ce ;
2223
2235
}
2224
2236
/* }}} */
2225
2237
2226
- static void zend_do_traits_property_and_constant_binding (zend_class_entry * ce , zend_class_entry * * traits ) /* {{{ */
2238
+ static void zend_do_traits_property_binding (zend_class_entry * ce , zend_class_entry * * traits ) /* {{{ */
2227
2239
{
2228
2240
size_t i ;
2229
2241
zend_property_info * property_info ;
@@ -2232,8 +2244,6 @@ static void zend_do_traits_property_and_constant_binding(zend_class_entry *ce, z
2232
2244
zend_string * prop_name ;
2233
2245
zval * prop_value ;
2234
2246
zend_string * doc_comment ;
2235
- zend_string * constant_name ;
2236
- zend_class_constant * constant ;
2237
2247
2238
2248
/* In the following steps the properties are inserted into the property table
2239
2249
* for that, a very strict approach is applied:
@@ -2244,10 +2254,6 @@ static void zend_do_traits_property_and_constant_binding(zend_class_entry *ce, z
2244
2254
if (!traits [i ]) {
2245
2255
continue ;
2246
2256
}
2247
- ZEND_HASH_MAP_FOREACH_STR_KEY_PTR (& traits [i ]-> constants_table , constant_name , constant ) {
2248
- do_inherit_trait_constant (constant_name , constant , ce , traits , i );
2249
- } ZEND_HASH_FOREACH_END ();
2250
-
2251
2257
ZEND_HASH_MAP_FOREACH_STR_KEY_PTR (& traits [i ]-> properties_info , prop_name , property_info ) {
2252
2258
uint32_t flags = property_info -> flags ;
2253
2259
@@ -2338,8 +2344,9 @@ static void zend_do_bind_traits(zend_class_entry *ce, zend_class_entry **traits)
2338
2344
efree (exclude_tables );
2339
2345
}
2340
2346
2341
- /* then flatten the properties into it, to, mostly to notify developer about problems */
2342
- zend_do_traits_property_and_constant_binding (ce , traits );
2347
+ /* then flatten the constants and properties into it, to, mostly to notify developer about problems */
2348
+ zend_do_traits_constant_binding (ce , traits );
2349
+ zend_do_traits_property_binding (ce , traits );
2343
2350
}
2344
2351
/* }}} */
2345
2352
0 commit comments