@@ -114,6 +114,7 @@ PHPAPI zend_class_entry *reflection_zend_extension_ptr;
114
114
typedef struct _property_reference {
115
115
zend_class_entry * ce ;
116
116
zend_property_info prop ;
117
+ zend_string * unmangled_name ;
117
118
} property_reference ;
118
119
119
120
/* Struct for parameters */
@@ -137,7 +138,6 @@ typedef enum {
137
138
REF_TYPE_PARAMETER ,
138
139
REF_TYPE_TYPE ,
139
140
REF_TYPE_PROPERTY ,
140
- REF_TYPE_DYNAMIC_PROPERTY ,
141
141
REF_TYPE_CLASS_CONSTANT
142
142
} reflection_type_t ;
143
143
@@ -229,11 +229,8 @@ static void reflection_free_objects_storage(zend_object *object) /* {{{ */
229
229
_free_function (intern -> ptr );
230
230
break ;
231
231
case REF_TYPE_PROPERTY :
232
- efree (intern -> ptr );
233
- break ;
234
- case REF_TYPE_DYNAMIC_PROPERTY :
235
232
prop_reference = (property_reference * )intern -> ptr ;
236
- zend_string_release_ex (prop_reference -> prop . name , 0 );
233
+ zend_string_release_ex (prop_reference -> unmangled_name , 0 );
237
234
efree (intern -> ptr );
238
235
break ;
239
236
case REF_TYPE_GENERATOR :
@@ -277,7 +274,7 @@ static zval *reflection_instantiate(zend_class_entry *pce, zval *object) /* {{{
277
274
278
275
static void _const_string (smart_str * str , char * name , zval * value , char * indent );
279
276
static void _function_string (smart_str * str , zend_function * fptr , zend_class_entry * scope , char * indent );
280
- static void _property_string (smart_str * str , zend_property_info * prop , char * prop_name , char * indent );
277
+ static void _property_string (smart_str * str , zend_property_info * prop , const char * prop_name , char * indent );
281
278
static void _class_const_string (smart_str * str , char * name , zend_class_constant * c , char * indent );
282
279
static void _class_string (smart_str * str , zend_class_entry * ce , zval * obj , char * indent );
283
280
static void _extension_string (smart_str * str , zend_module_entry * module , char * indent );
@@ -832,10 +829,8 @@ static void _function_string(smart_str *str, zend_function *fptr, zend_class_ent
832
829
/* }}} */
833
830
834
831
/* {{{ _property_string */
835
- static void _property_string (smart_str * str , zend_property_info * prop , char * prop_name , char * indent )
832
+ static void _property_string (smart_str * str , zend_property_info * prop , const char * prop_name , char * indent )
836
833
{
837
- const char * class_name ;
838
-
839
834
smart_str_append_printf (str , "%sProperty [ " , indent );
840
835
if (!prop ) {
841
836
smart_str_append_printf (str , "<dynamic> public $%s" , prop_name );
@@ -860,11 +855,13 @@ static void _property_string(smart_str *str, zend_property_info *prop, char *pro
860
855
smart_str_appends (str , "protected " );
861
856
break ;
862
857
}
863
- if (prop -> flags & ZEND_ACC_STATIC ) {
858
+ if (prop -> flags & ZEND_ACC_STATIC ) {
864
859
smart_str_appends (str , "static " );
865
860
}
866
-
867
- zend_unmangle_property_name (prop -> name , & class_name , (const char * * )& prop_name );
861
+ if (!prop_name ) {
862
+ const char * class_name ;
863
+ zend_unmangle_property_name (prop -> name , & class_name , & prop_name );
864
+ }
868
865
smart_str_append_printf (str , "$%s" , prop_name );
869
866
}
870
867
@@ -1235,23 +1232,19 @@ static void reflection_method_factory(zend_class_entry *ce, zend_function *metho
1235
1232
/* }}} */
1236
1233
1237
1234
/* {{{ reflection_property_factory */
1238
- static void reflection_property_factory (zend_class_entry * ce , zend_property_info * prop , zval * object )
1235
+ static void reflection_property_factory (zend_class_entry * ce , zend_string * name , zend_property_info * prop , zval * object )
1239
1236
{
1240
1237
reflection_object * intern ;
1241
- zval name ;
1238
+ zval propname ;
1242
1239
zval classname ;
1243
1240
property_reference * reference ;
1244
- const char * class_name , * prop_name ;
1245
- size_t prop_name_len ;
1246
-
1247
- zend_unmangle_property_name_ex (prop -> name , & class_name , & prop_name , & prop_name_len );
1248
1241
1249
1242
if (!(prop -> flags & ZEND_ACC_PRIVATE )) {
1250
1243
/* we have to search the class hierarchy for this (implicit) public or protected property */
1251
1244
zend_class_entry * tmp_ce = ce , * store_ce = ce ;
1252
1245
zend_property_info * tmp_info = NULL ;
1253
1246
1254
- while (tmp_ce && (tmp_info = zend_hash_str_find_ptr (& tmp_ce -> properties_info , prop_name , prop_name_len )) == NULL ) {
1247
+ while (tmp_ce && (tmp_info = zend_hash_find_ptr (& tmp_ce -> properties_info , name )) == NULL ) {
1255
1248
ce = tmp_ce ;
1256
1249
tmp_ce = tmp_ce -> parent ;
1257
1250
}
@@ -1263,23 +1256,31 @@ static void reflection_property_factory(zend_class_entry *ce, zend_property_info
1263
1256
}
1264
1257
}
1265
1258
1266
- ZVAL_STRINGL ( & name , prop_name , prop_name_len );
1259
+ ZVAL_STR_COPY ( & propname , name );
1267
1260
ZVAL_STR_COPY (& classname , prop -> ce -> name );
1268
1261
1269
1262
reflection_instantiate (reflection_property_ptr , object );
1270
1263
intern = Z_REFLECTION_P (object );
1271
1264
reference = (property_reference * ) emalloc (sizeof (property_reference ));
1272
1265
reference -> ce = ce ;
1273
1266
reference -> prop = * prop ;
1267
+ reference -> unmangled_name = zend_string_copy (name );
1274
1268
intern -> ptr = reference ;
1275
1269
intern -> ref_type = REF_TYPE_PROPERTY ;
1276
1270
intern -> ce = ce ;
1277
1271
intern -> ignore_visibility = 0 ;
1278
- reflection_update_property_name (object , & name );
1272
+ reflection_update_property_name (object , & propname );
1279
1273
reflection_update_property_class (object , & classname );
1280
1274
}
1281
1275
/* }}} */
1282
1276
1277
+ static void reflection_property_factory_str (zend_class_entry * ce , const char * name_str , size_t name_len , zend_property_info * prop , zval * object )
1278
+ {
1279
+ zend_string * name = zend_string_init (name_str , name_len , 0 );
1280
+ reflection_property_factory (ce , name , prop , object );
1281
+ zend_string_release (name );
1282
+ }
1283
+
1283
1284
/* {{{ reflection_class_constant_factory */
1284
1285
static void reflection_class_constant_factory (zend_class_entry * ce , zend_string * name_str , zend_class_constant * constant , zval * object )
1285
1286
{
@@ -4289,21 +4290,19 @@ ZEND_METHOD(reflection_class, getProperty)
4289
4290
GET_REFLECTION_OBJECT_PTR (ce );
4290
4291
if ((property_info = zend_hash_find_ptr (& ce -> properties_info , name )) != NULL ) {
4291
4292
if ((property_info -> flags & ZEND_ACC_SHADOW ) == 0 ) {
4292
- reflection_property_factory (ce , property_info , return_value );
4293
+ reflection_property_factory (ce , name , property_info , return_value );
4293
4294
return ;
4294
4295
}
4295
4296
} else if (Z_TYPE (intern -> obj ) != IS_UNDEF ) {
4296
4297
/* Check for dynamic properties */
4297
4298
if (zend_hash_exists (Z_OBJ_HT (intern -> obj )-> get_properties (& intern -> obj ), name )) {
4298
4299
zend_property_info property_info_tmp ;
4299
4300
property_info_tmp .flags = ZEND_ACC_IMPLICIT_PUBLIC ;
4300
- property_info_tmp .name = zend_string_copy ( name ) ;
4301
+ property_info_tmp .name = name ;
4301
4302
property_info_tmp .doc_comment = NULL ;
4302
4303
property_info_tmp .ce = ce ;
4303
4304
4304
- reflection_property_factory (ce , & property_info_tmp , return_value );
4305
- intern = Z_REFLECTION_P (return_value );
4306
- intern -> ref_type = REF_TYPE_DYNAMIC_PROPERTY ;
4305
+ reflection_property_factory (ce , name , & property_info_tmp , return_value );
4307
4306
return ;
4308
4307
}
4309
4308
}
@@ -4333,7 +4332,7 @@ ZEND_METHOD(reflection_class, getProperty)
4333
4332
ce = ce2 ;
4334
4333
4335
4334
if ((property_info = zend_hash_str_find_ptr (& ce -> properties_info , str_name , str_name_len )) != NULL && (property_info -> flags & ZEND_ACC_SHADOW ) == 0 ) {
4336
- reflection_property_factory (ce , property_info , return_value );
4335
+ reflection_property_factory_str (ce , str_name , str_name_len , property_info , return_value );
4337
4336
return ;
4338
4337
}
4339
4338
}
@@ -4356,7 +4355,10 @@ static int _addproperty(zval *el, int num_args, va_list args, zend_hash_key *has
4356
4355
}
4357
4356
4358
4357
if (pptr -> flags & filter ) {
4359
- reflection_property_factory (ce , pptr , & property );
4358
+ const char * class_name , * prop_name ;
4359
+ size_t prop_name_len ;
4360
+ zend_unmangle_property_name_ex (pptr -> name , & class_name , & prop_name , & prop_name_len );
4361
+ reflection_property_factory_str (ce , prop_name , prop_name_len , pptr , & property );
4360
4362
add_next_index_zval (retval , & property );
4361
4363
}
4362
4364
return 0 ;
@@ -4389,7 +4391,7 @@ static int _adddynproperty(zval *ptr, int num_args, va_list args, zend_hash_key
4389
4391
property_info .name = hash_key -> key ;
4390
4392
property_info .ce = ce ;
4391
4393
property_info .offset = -1 ;
4392
- reflection_property_factory (ce , & property_info , & property );
4394
+ reflection_property_factory (ce , hash_key -> key , & property_info , & property );
4393
4395
add_next_index_zval (retval , & property );
4394
4396
}
4395
4397
return 0 ;
@@ -5361,13 +5363,14 @@ ZEND_METHOD(reflection_property, __construct)
5361
5363
reference = (property_reference * ) emalloc (sizeof (property_reference ));
5362
5364
if (dynam_prop ) {
5363
5365
reference -> prop .flags = ZEND_ACC_IMPLICIT_PUBLIC ;
5364
- reference -> prop .name = Z_STR ( propname ) ;
5366
+ reference -> prop .name = name ;
5365
5367
reference -> prop .doc_comment = NULL ;
5366
5368
reference -> prop .ce = ce ;
5367
5369
} else {
5368
5370
reference -> prop = * property_info ;
5369
5371
}
5370
5372
reference -> ce = ce ;
5373
+ reference -> unmangled_name = zend_string_copy (name );
5371
5374
intern -> ptr = reference ;
5372
5375
intern -> ref_type = REF_TYPE_PROPERTY ;
5373
5376
intern -> ce = ce ;
@@ -5387,7 +5390,7 @@ ZEND_METHOD(reflection_property, __toString)
5387
5390
return ;
5388
5391
}
5389
5392
GET_REFLECTION_OBJECT_PTR (ref );
5390
- _property_string (& str , & ref -> prop , NULL , "" );
5393
+ _property_string (& str , & ref -> prop , ZSTR_VAL ( ref -> unmangled_name ) , "" );
5391
5394
RETURN_STR (smart_str_extract (& str ));
5392
5395
}
5393
5396
/* }}} */
@@ -5505,8 +5508,6 @@ ZEND_METHOD(reflection_property, getValue)
5505
5508
ZVAL_DEREF (member_p );
5506
5509
ZVAL_COPY (return_value , member_p );
5507
5510
} else {
5508
- const char * class_name , * prop_name ;
5509
- size_t prop_name_len ;
5510
5511
zval rv ;
5511
5512
5512
5513
if (zend_parse_parameters (ZEND_NUM_ARGS (), "o" , & object ) == FAILURE ) {
@@ -5518,8 +5519,7 @@ ZEND_METHOD(reflection_property, getValue)
5518
5519
/* Returns from this function */
5519
5520
}
5520
5521
5521
- zend_unmangle_property_name_ex (ref -> prop .name , & class_name , & prop_name , & prop_name_len );
5522
- member_p = zend_read_property (ref -> ce , object , prop_name , prop_name_len , 0 , & rv );
5522
+ member_p = zend_read_property_ex (ref -> ce , object , ref -> unmangled_name , 0 , & rv );
5523
5523
if (member_p != & rv ) {
5524
5524
ZVAL_DEREF (member_p );
5525
5525
ZVAL_COPY (return_value , member_p );
@@ -5583,15 +5583,11 @@ ZEND_METHOD(reflection_property, setValue)
5583
5583
zval_ptr_dtor (& garbage );
5584
5584
}
5585
5585
} else {
5586
- const char * class_name , * prop_name ;
5587
- size_t prop_name_len ;
5588
-
5589
5586
if (zend_parse_parameters (ZEND_NUM_ARGS (), "oz" , & object , & value ) == FAILURE ) {
5590
5587
return ;
5591
5588
}
5592
5589
5593
- zend_unmangle_property_name_ex (ref -> prop .name , & class_name , & prop_name , & prop_name_len );
5594
- zend_update_property (ref -> ce , object , prop_name , prop_name_len , value );
5590
+ zend_update_property_ex (ref -> ce , object , ref -> unmangled_name , value );
5595
5591
}
5596
5592
}
5597
5593
/* }}} */
@@ -5604,20 +5600,14 @@ ZEND_METHOD(reflection_property, getDeclaringClass)
5604
5600
property_reference * ref ;
5605
5601
zend_class_entry * tmp_ce , * ce ;
5606
5602
zend_property_info * tmp_info ;
5607
- const char * prop_name , * class_name ;
5608
- size_t prop_name_len ;
5609
5603
5610
5604
if (zend_parse_parameters_none () == FAILURE ) {
5611
5605
return ;
5612
5606
}
5613
5607
GET_REFLECTION_OBJECT_PTR (ref );
5614
5608
5615
- if (zend_unmangle_property_name_ex (ref -> prop .name , & class_name , & prop_name , & prop_name_len ) != SUCCESS ) {
5616
- RETURN_FALSE ;
5617
- }
5618
-
5619
5609
ce = tmp_ce = ref -> ce ;
5620
- while (tmp_ce && (tmp_info = zend_hash_str_find_ptr (& tmp_ce -> properties_info , prop_name , prop_name_len )) != NULL ) {
5610
+ while (tmp_ce && (tmp_info = zend_hash_find_ptr (& tmp_ce -> properties_info , ref -> unmangled_name )) != NULL ) {
5621
5611
if (tmp_info -> flags & ZEND_ACC_PRIVATE || tmp_info -> flags & ZEND_ACC_SHADOW ) {
5622
5612
/* it's a private property, so it can't be inherited */
5623
5613
break ;
0 commit comments