@@ -112,9 +112,8 @@ PHPAPI zend_class_entry *reflection_reference_ptr;
112
112
113
113
/* Struct for properties */
114
114
typedef struct _property_reference {
115
- zend_property_info prop ;
115
+ zend_property_info * prop ;
116
116
zend_string * unmangled_name ;
117
- zend_bool dynamic ;
118
117
} property_reference ;
119
118
120
119
/* Struct for parameters */
@@ -159,6 +158,10 @@ static inline reflection_object *reflection_object_from_obj(zend_object *obj) {
159
158
160
159
static zend_object_handlers reflection_object_handlers ;
161
160
161
+ static uint32_t zend_always_inline prop_get_flags (property_reference * ref ) {
162
+ return ref -> prop ? ref -> prop -> flags : ZEND_ACC_PUBLIC ;
163
+ }
164
+
162
165
static inline zend_bool is_closure_invoke (zend_class_entry * ce , zend_string * lcname ) {
163
166
return ce == zend_ce_closure
164
167
&& zend_string_equals_literal (lcname , ZEND_INVOKE_FUNC_NAME );
@@ -280,7 +283,7 @@ static zval *reflection_instantiate(zend_class_entry *pce, zval *object) /* {{{
280
283
281
284
static void _const_string (smart_str * str , char * name , zval * value , char * indent );
282
285
static void _function_string (smart_str * str , zend_function * fptr , zend_class_entry * scope , char * indent );
283
- static void _property_string (smart_str * str , zend_property_info * prop , const char * prop_name , char * indent , zend_bool dynamic );
286
+ static void _property_string (smart_str * str , zend_property_info * prop , const char * prop_name , char * indent );
284
287
static void _class_const_string (smart_str * str , char * name , zend_class_constant * c , char * indent );
285
288
static void _class_string (smart_str * str , zend_class_entry * ce , zval * obj , char * indent );
286
289
static void _extension_string (smart_str * str , zend_module_entry * module , char * indent );
@@ -395,7 +398,7 @@ static void _class_string(smart_str *str, zend_class_entry *ce, zval *obj, char
395
398
396
399
ZEND_HASH_FOREACH_PTR (& ce -> properties_info , prop ) {
397
400
if ((prop -> flags & ZEND_ACC_STATIC ) && (!(prop -> flags & ZEND_ACC_PRIVATE ) || prop -> ce == ce )) {
398
- _property_string (str , prop , NULL , ZSTR_VAL (sub_indent ), 0 );
401
+ _property_string (str , prop , NULL , ZSTR_VAL (sub_indent ));
399
402
}
400
403
} ZEND_HASH_FOREACH_END ();
401
404
}
@@ -443,7 +446,7 @@ static void _class_string(smart_str *str, zend_class_entry *ce, zval *obj, char
443
446
ZEND_HASH_FOREACH_PTR (& ce -> properties_info , prop ) {
444
447
if (!(prop -> flags & ZEND_ACC_STATIC )
445
448
&& (!(prop -> flags & ZEND_ACC_PRIVATE ) || prop -> ce == ce )) {
446
- _property_string (str , prop , NULL , ZSTR_VAL (sub_indent ), 0 );
449
+ _property_string (str , prop , NULL , ZSTR_VAL (sub_indent ));
447
450
}
448
451
} ZEND_HASH_FOREACH_END ();
449
452
}
@@ -460,7 +463,7 @@ static void _class_string(smart_str *str, zend_class_entry *ce, zval *obj, char
460
463
if (prop_name && ZSTR_LEN (prop_name ) && ZSTR_VAL (prop_name )[0 ]) { /* skip all private and protected properties */
461
464
if (!zend_hash_exists (& ce -> properties_info , prop_name )) {
462
465
count ++ ;
463
- _property_string (& prop_str , NULL , ZSTR_VAL (prop_name ), ZSTR_VAL (sub_indent ), 0 );
466
+ _property_string (& prop_str , NULL , ZSTR_VAL (prop_name ), ZSTR_VAL (sub_indent ));
464
467
}
465
468
}
466
469
} ZEND_HASH_FOREACH_END ();
@@ -812,18 +815,14 @@ static void _function_string(smart_str *str, zend_function *fptr, zend_class_ent
812
815
/* }}} */
813
816
814
817
/* {{{ _property_string */
815
- static void _property_string (smart_str * str , zend_property_info * prop , const char * prop_name , char * indent , zend_bool dynamic )
818
+ static void _property_string (smart_str * str , zend_property_info * prop , const char * prop_name , char * indent )
816
819
{
817
820
smart_str_append_printf (str , "%sProperty [ " , indent );
818
821
if (!prop ) {
819
822
smart_str_append_printf (str , "<dynamic> public $%s" , prop_name );
820
823
} else {
821
824
if (!(prop -> flags & ZEND_ACC_STATIC )) {
822
- if (dynamic ) {
823
- smart_str_appends (str , "<implicit> " );
824
- } else {
825
- smart_str_appends (str , "<default> " );
826
- }
825
+ smart_str_appends (str , "<default> " );
827
826
}
828
827
829
828
/* These are mutually exclusive */
@@ -1192,12 +1191,12 @@ static void reflection_method_factory(zend_class_entry *ce, zend_function *metho
1192
1191
/* }}} */
1193
1192
1194
1193
/* {{{ reflection_property_factory */
1195
- static void reflection_property_factory (zend_class_entry * ce , zend_string * name , zend_property_info * prop , zval * object , zend_bool dynamic )
1194
+ static void reflection_property_factory (zend_class_entry * ce , zend_string * name , zend_property_info * prop , zval * object )
1196
1195
{
1197
1196
reflection_object * intern ;
1198
1197
property_reference * reference ;
1199
1198
1200
- if (!(prop -> flags & ZEND_ACC_PRIVATE )) {
1199
+ if (!prop || ! (prop -> flags & ZEND_ACC_PRIVATE )) {
1201
1200
/* we have to search the class hierarchy for this (implicit) public or protected property */
1202
1201
zend_class_entry * tmp_ce = ce , * store_ce = ce ;
1203
1202
zend_property_info * tmp_info = NULL ;
@@ -1217,22 +1216,21 @@ static void reflection_property_factory(zend_class_entry *ce, zend_string *name,
1217
1216
reflection_instantiate (reflection_property_ptr , object );
1218
1217
intern = Z_REFLECTION_P (object );
1219
1218
reference = (property_reference * ) emalloc (sizeof (property_reference ));
1220
- reference -> prop = * prop ;
1219
+ reference -> prop = prop ;
1221
1220
reference -> unmangled_name = zend_string_copy (name );
1222
- reference -> dynamic = dynamic ;
1223
1221
intern -> ptr = reference ;
1224
1222
intern -> ref_type = REF_TYPE_PROPERTY ;
1225
1223
intern -> ce = ce ;
1226
1224
intern -> ignore_visibility = 0 ;
1227
1225
ZVAL_STR_COPY (reflection_prop_name (object ), name );
1228
- ZVAL_STR_COPY (reflection_prop_class (object ), prop -> ce -> name );
1226
+ ZVAL_STR_COPY (reflection_prop_class (object ), prop ? prop -> ce -> name : ce -> name );
1229
1227
}
1230
1228
/* }}} */
1231
1229
1232
1230
static void reflection_property_factory_str (zend_class_entry * ce , const char * name_str , size_t name_len , zend_property_info * prop , zval * object )
1233
1231
{
1234
1232
zend_string * name = zend_string_init (name_str , name_len , 0 );
1235
- reflection_property_factory (ce , name , prop , object , 0 );
1233
+ reflection_property_factory (ce , name , prop , object );
1236
1234
zend_string_release (name );
1237
1235
}
1238
1236
@@ -4212,19 +4210,13 @@ ZEND_METHOD(reflection_class, getProperty)
4212
4210
GET_REFLECTION_OBJECT_PTR (ce );
4213
4211
if ((property_info = zend_hash_find_ptr (& ce -> properties_info , name )) != NULL ) {
4214
4212
if (!(property_info -> flags & ZEND_ACC_PRIVATE ) || property_info -> ce == ce ) {
4215
- reflection_property_factory (ce , name , property_info , return_value , 0 );
4213
+ reflection_property_factory (ce , name , property_info , return_value );
4216
4214
return ;
4217
4215
}
4218
4216
} else if (Z_TYPE (intern -> obj ) != IS_UNDEF ) {
4219
4217
/* Check for dynamic properties */
4220
4218
if (zend_hash_exists (Z_OBJ_HT (intern -> obj )-> get_properties (Z_OBJ (intern -> obj )), name )) {
4221
- zend_property_info property_info_tmp ;
4222
- property_info_tmp .flags = ZEND_ACC_PUBLIC ;
4223
- property_info_tmp .name = name ;
4224
- property_info_tmp .doc_comment = NULL ;
4225
- property_info_tmp .ce = ce ;
4226
-
4227
- reflection_property_factory (ce , name , & property_info_tmp , return_value , 1 );
4219
+ reflection_property_factory (ce , name , NULL , return_value );
4228
4220
return ;
4229
4221
}
4230
4222
}
@@ -4275,7 +4267,7 @@ static void _addproperty(zend_property_info *pptr, zend_string *key, zend_class_
4275
4267
4276
4268
if (pptr -> flags & filter ) {
4277
4269
zval property ;
4278
- reflection_property_factory (ce , key , pptr , & property , 0 );
4270
+ reflection_property_factory (ce , key , pptr , & property );
4279
4271
add_next_index_zval (retval , & property );
4280
4272
}
4281
4273
}
@@ -4284,7 +4276,6 @@ static void _addproperty(zend_property_info *pptr, zend_string *key, zend_class_
4284
4276
/* {{{ _adddynproperty */
4285
4277
static void _adddynproperty (zval * ptr , zend_string * key , zend_class_entry * ce , zval * retval )
4286
4278
{
4287
- zend_property_info property_info ;
4288
4279
zval property ;
4289
4280
4290
4281
/* under some circumstances, the properties hash table may contain numeric
@@ -4299,12 +4290,7 @@ static void _adddynproperty(zval *ptr, zend_string *key, zend_class_entry *ce, z
4299
4290
return ;
4300
4291
}
4301
4292
4302
- property_info .doc_comment = NULL ;
4303
- property_info .flags = ZEND_ACC_PUBLIC ;
4304
- property_info .name = key ;
4305
- property_info .ce = ce ;
4306
- property_info .offset = -1 ;
4307
- reflection_property_factory (ce , key , & property_info , & property , 1 );
4293
+ reflection_property_factory (ce , key , NULL , & property );
4308
4294
add_next_index_zval (retval , & property );
4309
4295
}
4310
4296
/* }}} */
@@ -5281,16 +5267,7 @@ ZEND_METHOD(reflection_property, __construct)
5281
5267
}
5282
5268
5283
5269
reference = (property_reference * ) emalloc (sizeof (property_reference ));
5284
- if (dynam_prop ) {
5285
- reference -> prop .flags = ZEND_ACC_PUBLIC ;
5286
- reference -> prop .name = name ;
5287
- reference -> prop .doc_comment = NULL ;
5288
- reference -> prop .ce = ce ;
5289
- reference -> dynamic = 1 ;
5290
- } else {
5291
- reference -> prop = * property_info ;
5292
- reference -> dynamic = 0 ;
5293
- }
5270
+ reference -> prop = dynam_prop ? NULL : property_info ;
5294
5271
reference -> unmangled_name = zend_string_copy (name );
5295
5272
intern -> ptr = reference ;
5296
5273
intern -> ref_type = REF_TYPE_PROPERTY ;
@@ -5311,7 +5288,7 @@ ZEND_METHOD(reflection_property, __toString)
5311
5288
return ;
5312
5289
}
5313
5290
GET_REFLECTION_OBJECT_PTR (ref );
5314
- _property_string (& str , & ref -> prop , ZSTR_VAL (ref -> unmangled_name ), "" , ref -> dynamic );
5291
+ _property_string (& str , ref -> prop , ZSTR_VAL (ref -> unmangled_name ), "" );
5315
5292
RETURN_STR (smart_str_extract (& str ));
5316
5293
}
5317
5294
/* }}} */
@@ -5336,7 +5313,7 @@ static void _property_check_flag(INTERNAL_FUNCTION_PARAMETERS, int mask) /* {{{
5336
5313
return ;
5337
5314
}
5338
5315
GET_REFLECTION_OBJECT_PTR (ref );
5339
- RETURN_BOOL (ref -> prop . flags & mask );
5316
+ RETURN_BOOL (prop_get_flags ( ref ) & mask );
5340
5317
}
5341
5318
/* }}} */
5342
5319
@@ -5383,7 +5360,7 @@ ZEND_METHOD(reflection_property, isDefault)
5383
5360
return ;
5384
5361
}
5385
5362
GET_REFLECTION_OBJECT_PTR (ref );
5386
- RETURN_BOOL (! ref -> dynamic );
5363
+ RETURN_BOOL (ref -> prop != NULL );
5387
5364
}
5388
5365
/* }}} */
5389
5366
@@ -5400,7 +5377,7 @@ ZEND_METHOD(reflection_property, getModifiers)
5400
5377
}
5401
5378
GET_REFLECTION_OBJECT_PTR (ref );
5402
5379
5403
- RETURN_LONG ((ref -> prop . flags & keep_flags ) );
5380
+ RETURN_LONG (prop_get_flags (ref ) & keep_flags );
5404
5381
}
5405
5382
/* }}} */
5406
5383
@@ -5415,14 +5392,14 @@ ZEND_METHOD(reflection_property, getValue)
5415
5392
5416
5393
GET_REFLECTION_OBJECT_PTR (ref );
5417
5394
5418
- if (!(ref -> prop . flags & ZEND_ACC_PUBLIC ) && intern -> ignore_visibility == 0 ) {
5395
+ if (!(prop_get_flags ( ref ) & ZEND_ACC_PUBLIC ) && intern -> ignore_visibility == 0 ) {
5419
5396
name = _default_load_name (ZEND_THIS );
5420
5397
zend_throw_exception_ex (reflection_exception_ptr , 0 ,
5421
5398
"Cannot access non-public member %s::$%s" , ZSTR_VAL (intern -> ce -> name ), Z_STRVAL_P (name ));
5422
5399
return ;
5423
5400
}
5424
5401
5425
- if (ref -> prop . flags & ZEND_ACC_STATIC ) {
5402
+ if (prop_get_flags ( ref ) & ZEND_ACC_STATIC ) {
5426
5403
member_p = zend_read_static_property_ex (intern -> ce , ref -> unmangled_name , 0 );
5427
5404
if (member_p ) {
5428
5405
ZVAL_COPY_DEREF (return_value , member_p );
@@ -5434,7 +5411,8 @@ ZEND_METHOD(reflection_property, getValue)
5434
5411
return ;
5435
5412
}
5436
5413
5437
- if (!instanceof_function (Z_OBJCE_P (object ), ref -> prop .ce )) {
5414
+ /* TODO: Should this always use intern->ce? */
5415
+ if (!instanceof_function (Z_OBJCE_P (object ), ref -> prop ? ref -> prop -> ce : intern -> ce )) {
5438
5416
_DO_THROW ("Given object is not an instance of the class this property was declared in" );
5439
5417
return ;
5440
5418
}
@@ -5464,14 +5442,14 @@ ZEND_METHOD(reflection_property, setValue)
5464
5442
5465
5443
GET_REFLECTION_OBJECT_PTR (ref );
5466
5444
5467
- if (!(ref -> prop . flags & ZEND_ACC_PUBLIC ) && intern -> ignore_visibility == 0 ) {
5445
+ if (!(prop_get_flags ( ref ) & ZEND_ACC_PUBLIC ) && intern -> ignore_visibility == 0 ) {
5468
5446
name = _default_load_name (ZEND_THIS );
5469
5447
zend_throw_exception_ex (reflection_exception_ptr , 0 ,
5470
5448
"Cannot access non-public member %s::$%s" , ZSTR_VAL (intern -> ce -> name ), Z_STRVAL_P (name ));
5471
5449
return ;
5472
5450
}
5473
5451
5474
- if (ref -> prop . flags & ZEND_ACC_STATIC ) {
5452
+ if (prop_get_flags ( ref ) & ZEND_ACC_STATIC ) {
5475
5453
if (zend_parse_parameters_ex (ZEND_PARSE_PARAMS_QUIET , ZEND_NUM_ARGS (), "z" , & value ) == FAILURE ) {
5476
5454
if (zend_parse_parameters (ZEND_NUM_ARGS (), "zz" , & tmp , & value ) == FAILURE ) {
5477
5455
return ;
@@ -5500,14 +5478,14 @@ ZEND_METHOD(reflection_property, isInitialized)
5500
5478
5501
5479
GET_REFLECTION_OBJECT_PTR (ref );
5502
5480
5503
- if (!(ref -> prop . flags & ZEND_ACC_PUBLIC ) && intern -> ignore_visibility == 0 ) {
5481
+ if (!(prop_get_flags ( ref ) & ZEND_ACC_PUBLIC ) && intern -> ignore_visibility == 0 ) {
5504
5482
name = _default_load_name (getThis ());
5505
5483
zend_throw_exception_ex (reflection_exception_ptr , 0 ,
5506
5484
"Cannot access non-public member %s::$%s" , ZSTR_VAL (intern -> ce -> name ), Z_STRVAL_P (name ));
5507
5485
return ;
5508
5486
}
5509
5487
5510
- if (ref -> prop . flags & ZEND_ACC_STATIC ) {
5488
+ if (prop_get_flags ( ref ) & ZEND_ACC_STATIC ) {
5511
5489
member_p = zend_read_static_property_ex (intern -> ce , ref -> unmangled_name , 1 );
5512
5490
if (member_p ) {
5513
5491
RETURN_BOOL (!Z_ISUNDEF_P (member_p ));
@@ -5521,7 +5499,8 @@ ZEND_METHOD(reflection_property, isInitialized)
5521
5499
return ;
5522
5500
}
5523
5501
5524
- if (!instanceof_function (Z_OBJCE_P (object ), ref -> prop .ce )) {
5502
+ /* TODO: Should this always use intern->ce? */
5503
+ if (!instanceof_function (Z_OBJCE_P (object ), ref -> prop ? ref -> prop -> ce : intern -> ce )) {
5525
5504
_DO_THROW ("Given object is not an instance of the class this property was declared in" );
5526
5505
return ;
5527
5506
}
@@ -5579,8 +5558,8 @@ ZEND_METHOD(reflection_property, getDocComment)
5579
5558
return ;
5580
5559
}
5581
5560
GET_REFLECTION_OBJECT_PTR (ref );
5582
- if (ref -> prop . doc_comment ) {
5583
- RETURN_STR_COPY (ref -> prop . doc_comment );
5561
+ if (ref -> prop && ref -> prop -> doc_comment ) {
5562
+ RETURN_STR_COPY (ref -> prop -> doc_comment );
5584
5563
}
5585
5564
RETURN_FALSE ;
5586
5565
}
@@ -5616,11 +5595,11 @@ ZEND_METHOD(reflection_property, getType)
5616
5595
5617
5596
GET_REFLECTION_OBJECT_PTR (ref );
5618
5597
5619
- if (!ZEND_TYPE_IS_SET (ref -> prop . type )) {
5598
+ if (!ref -> prop || ! ZEND_TYPE_IS_SET (ref -> prop -> type )) {
5620
5599
RETURN_NULL ();
5621
5600
}
5622
5601
5623
- reflection_type_factory (ref -> prop . type , return_value );
5602
+ reflection_type_factory (ref -> prop -> type , return_value );
5624
5603
}
5625
5604
/* }}} */
5626
5605
@@ -5637,7 +5616,7 @@ ZEND_METHOD(reflection_property, hasType)
5637
5616
5638
5617
GET_REFLECTION_OBJECT_PTR (ref );
5639
5618
5640
- RETVAL_BOOL (ZEND_TYPE_IS_SET (ref -> prop . type ));
5619
+ RETVAL_BOOL (ref -> prop && ZEND_TYPE_IS_SET (ref -> prop -> type ));
5641
5620
}
5642
5621
/* }}} */
5643
5622
0 commit comments