@@ -1480,25 +1480,24 @@ ZEND_METHOD(Reflection, getModifierNames)
1480
1480
ZEND_METHOD (ReflectionFunction , __construct )
1481
1481
{
1482
1482
zval * object ;
1483
- zval * closure = NULL ;
1483
+ zend_object * closure_obj = NULL ;
1484
1484
reflection_object * intern ;
1485
1485
zend_function * fptr ;
1486
1486
zend_string * fname , * lcname ;
1487
1487
1488
1488
object = ZEND_THIS ;
1489
1489
intern = Z_REFLECTION_P (object );
1490
1490
1491
- if (zend_parse_parameters_ex (ZEND_PARSE_PARAMS_QUIET , ZEND_NUM_ARGS (), "O" , & closure , zend_ce_closure ) == SUCCESS ) {
1492
- fptr = (zend_function * )zend_get_closure_method_def (closure );
1493
- } else {
1494
- ALLOCA_FLAG (use_heap )
1495
-
1496
- if (zend_parse_parameters (ZEND_NUM_ARGS (), "S ", & fname ) == FAILURE ) {
1497
- RETURN_THROWS ();
1498
- }
1491
+ ZEND_PARSE_PARAMETERS_START (1 , 1 )
1492
+ Z_PARAM_STR_OR_OBJ_OF_CLASS (fname , closure_obj , zend_ce_closure )
1493
+ ZEND_PARSE_PARAMETERS_END ();
1499
1494
1495
+ if (closure_obj ) {
1496
+ fptr = (zend_function * )zend_get_closure_method_def (closure_obj );
1497
+ } else {
1500
1498
if (UNEXPECTED (ZSTR_VAL (fname )[0 ] == '\\' )) {
1501
1499
/* Ignore leading "\" */
1500
+ ALLOCA_FLAG (use_heap )
1502
1501
ZSTR_ALLOCA_ALLOC (lcname , ZSTR_LEN (fname ) - 1 , use_heap );
1503
1502
zend_str_tolower_copy (ZSTR_VAL (lcname ), ZSTR_VAL (fname ) + 1 , ZSTR_LEN (fname ) - 1 );
1504
1503
fptr = zend_fetch_function (lcname );
@@ -1519,8 +1518,8 @@ ZEND_METHOD(ReflectionFunction, __construct)
1519
1518
ZVAL_STR_COPY (reflection_prop_name (object ), fptr -> common .function_name );
1520
1519
intern -> ptr = fptr ;
1521
1520
intern -> ref_type = REF_TYPE_FUNCTION ;
1522
- if (closure ) {
1523
- ZVAL_OBJ_COPY (& intern -> obj , Z_OBJ_P ( closure ) );
1521
+ if (closure_obj ) {
1522
+ ZVAL_OBJ_COPY (& intern -> obj , closure_obj );
1524
1523
} else {
1525
1524
ZVAL_UNDEF (& intern -> obj );
1526
1525
}
@@ -1603,7 +1602,7 @@ ZEND_METHOD(ReflectionFunctionAbstract, getClosureScopeClass)
1603
1602
}
1604
1603
GET_REFLECTION_OBJECT ();
1605
1604
if (!Z_ISUNDEF (intern -> obj )) {
1606
- closure_func = zend_get_closure_method_def (& intern -> obj );
1605
+ closure_func = zend_get_closure_method_def (Z_OBJ ( intern -> obj ) );
1607
1606
if (closure_func && closure_func -> common .scope ) {
1608
1607
zend_reflection_class_factory (closure_func -> common .scope , return_value );
1609
1608
}
@@ -2315,7 +2314,7 @@ ZEND_METHOD(ReflectionParameter, __construct)
2315
2314
ce = Z_OBJCE_P (reference );
2316
2315
2317
2316
if (instanceof_function (ce , zend_ce_closure )) {
2318
- fptr = (zend_function * )zend_get_closure_method_def (reference );
2317
+ fptr = (zend_function * )zend_get_closure_method_def (Z_OBJ_P ( reference ) );
2319
2318
Z_ADDREF_P (reference );
2320
2319
is_closure = 1 ;
2321
2320
} else if ((fptr = zend_hash_find_ptr (& ce -> function_table , ZSTR_KNOWN (ZEND_STR_MAGIC_INVOKE ))) == NULL ) {
@@ -3017,7 +3016,6 @@ ZEND_METHOD(ReflectionMethod, __construct)
3017
3016
object = ZEND_THIS ;
3018
3017
intern = Z_REFLECTION_P (object );
3019
3018
3020
- /* Find the class entry */
3021
3019
switch (Z_TYPE_P (classname )) {
3022
3020
case IS_STRING :
3023
3021
if ((ce = zend_lookup_class (Z_STR_P (classname ))) == NULL ) {
@@ -3519,38 +3517,31 @@ ZEND_METHOD(ReflectionMethod, setAccessible)
3519
3517
/* {{{ Constructor. Throws an Exception in case the given class constant does not exist */
3520
3518
ZEND_METHOD (ReflectionClassConstant , __construct )
3521
3519
{
3522
- zval * classname , * object ;
3520
+ zval * object ;
3521
+ zend_string * classname_str ;
3522
+ zend_object * classname_obj ;
3523
3523
zend_string * constname ;
3524
3524
reflection_object * intern ;
3525
3525
zend_class_entry * ce ;
3526
3526
zend_class_constant * constant = NULL ;
3527
3527
3528
- if (zend_parse_parameters (ZEND_NUM_ARGS (), "zS" , & classname , & constname ) == FAILURE ) {
3529
- RETURN_THROWS ();
3528
+ ZEND_PARSE_PARAMETERS_START (2 , 2 )
3529
+ Z_PARAM_STR_OR_OBJ (classname_str , classname_obj )
3530
+ Z_PARAM_STR (constname )
3531
+ ZEND_PARSE_PARAMETERS_END ();
3532
+
3533
+ if (classname_obj ) {
3534
+ ce = classname_obj -> ce ;
3535
+ } else {
3536
+ if ((ce = zend_lookup_class (classname_str )) == NULL ) {
3537
+ zend_throw_exception_ex (reflection_exception_ptr , 0 , "Class \"%s\" does not exist" , ZSTR_VAL (classname_str ));
3538
+ RETURN_THROWS ();
3539
+ }
3530
3540
}
3531
3541
3532
3542
object = ZEND_THIS ;
3533
3543
intern = Z_REFLECTION_P (object );
3534
3544
3535
- /* Find the class entry */
3536
- switch (Z_TYPE_P (classname )) {
3537
- case IS_STRING :
3538
- if ((ce = zend_lookup_class (Z_STR_P (classname ))) == NULL ) {
3539
- zend_throw_exception_ex (reflection_exception_ptr , 0 ,
3540
- "Class \"%s\" does not exist" , Z_STRVAL_P (classname ));
3541
- RETURN_THROWS ();
3542
- }
3543
- break ;
3544
-
3545
- case IS_OBJECT :
3546
- ce = Z_OBJCE_P (classname );
3547
- break ;
3548
-
3549
- default :
3550
- zend_argument_error (reflection_exception_ptr , 1 , "must be of type object|string, %s given" , zend_zval_type_name (classname ));
3551
- RETURN_THROWS ();
3552
- }
3553
-
3554
3545
if ((constant = zend_hash_find_ptr (& ce -> constants_table , constname )) == NULL ) {
3555
3546
zend_throw_exception_ex (reflection_exception_ptr , 0 , "Constant %s::%s does not exist" , ZSTR_VAL (ce -> name ), ZSTR_VAL (constname ));
3556
3547
RETURN_THROWS ();
@@ -3814,7 +3805,7 @@ ZEND_METHOD(ReflectionClass, getStaticProperties)
3814
3805
GET_REFLECTION_OBJECT_PTR (ce );
3815
3806
3816
3807
if (UNEXPECTED (zend_update_class_constants (ce ) != SUCCESS )) {
3817
- return ;
3808
+ RETURN_THROWS () ;
3818
3809
}
3819
3810
3820
3811
if (ce -> default_static_members_count && !CE_STATIC_MEMBERS (ce )) {
@@ -3863,7 +3854,7 @@ ZEND_METHOD(ReflectionClass, getStaticPropertyValue)
3863
3854
GET_REFLECTION_OBJECT_PTR (ce );
3864
3855
3865
3856
if (UNEXPECTED (zend_update_class_constants (ce ) != SUCCESS )) {
3866
- return ;
3857
+ RETURN_THROWS () ;
3867
3858
}
3868
3859
3869
3860
old_scope = EG (fake_scope );
@@ -3901,7 +3892,7 @@ ZEND_METHOD(ReflectionClass, setStaticPropertyValue)
3901
3892
GET_REFLECTION_OBJECT_PTR (ce );
3902
3893
3903
3894
if (UNEXPECTED (zend_update_class_constants (ce ) != SUCCESS )) {
3904
- return ;
3895
+ RETURN_THROWS () ;
3905
3896
}
3906
3897
old_scope = EG (fake_scope );
3907
3898
EG (fake_scope ) = ce ;
@@ -3945,7 +3936,7 @@ ZEND_METHOD(ReflectionClass, getDefaultProperties)
3945
3936
GET_REFLECTION_OBJECT_PTR (ce );
3946
3937
array_init (return_value );
3947
3938
if (UNEXPECTED (zend_update_class_constants (ce ) != SUCCESS )) {
3948
- return ;
3939
+ RETURN_THROWS () ;
3949
3940
}
3950
3941
add_class_vars (ce , 1 , return_value );
3951
3942
add_class_vars (ce , 0 , return_value );
@@ -4967,38 +4958,30 @@ ZEND_METHOD(ReflectionClass, isSubclassOf)
4967
4958
{
4968
4959
reflection_object * intern , * argument ;
4969
4960
zend_class_entry * ce , * class_ce ;
4970
- zval * class_name ;
4961
+ zend_string * class_str ;
4962
+ zend_object * class_obj ;
4971
4963
4972
- GET_REFLECTION_OBJECT_PTR (ce );
4964
+ ZEND_PARSE_PARAMETERS_START (1 , 1 )
4965
+ Z_PARAM_STR_OR_OBJ_OF_CLASS (class_str , class_obj , reflection_class_ptr )
4966
+ ZEND_PARSE_PARAMETERS_END ();
4973
4967
4974
- if (zend_parse_parameters (ZEND_NUM_ARGS (), "z" , & class_name ) == FAILURE ) {
4975
- RETURN_THROWS ();
4976
- }
4968
+ if (class_obj ) {
4969
+ argument = reflection_object_from_obj (class_obj );
4970
+ if (argument -> ptr == NULL ) {
4971
+ zend_throw_error (NULL , "Internal error: Failed to retrieve the argument's reflection object" );
4972
+ RETURN_THROWS ();
4973
+ }
4977
4974
4978
- switch (Z_TYPE_P (class_name )) {
4979
- case IS_STRING :
4980
- if ((class_ce = zend_lookup_class (Z_STR_P (class_name ))) == NULL ) {
4981
- zend_throw_exception_ex (reflection_exception_ptr , 0 ,
4982
- "Class \"%s\" does not exist" , Z_STRVAL_P (class_name ));
4983
- RETURN_THROWS ();
4984
- }
4985
- break ;
4986
- case IS_OBJECT :
4987
- if (instanceof_function (Z_OBJCE_P (class_name ), reflection_class_ptr )) {
4988
- argument = Z_REFLECTION_P (class_name );
4989
- if (argument -> ptr == NULL ) {
4990
- zend_throw_error (NULL , "Internal error: Failed to retrieve the argument's reflection object" );
4991
- RETURN_THROWS ();
4992
- }
4993
- class_ce = argument -> ptr ;
4994
- break ;
4995
- }
4996
- /* no break */
4997
- default :
4998
- zend_argument_error (reflection_exception_ptr , 1 , "must be of type ReflectionClass|string, %s given" , zend_zval_type_name (class_name ));
4975
+ class_ce = argument -> ptr ;
4976
+ } else {
4977
+ if ((class_ce = zend_lookup_class (class_str )) == NULL ) {
4978
+ zend_throw_exception_ex (reflection_exception_ptr , 0 , "Class \"%s\" does not exist" , ZSTR_VAL (class_str ));
4999
4979
RETURN_THROWS ();
4980
+ }
5000
4981
}
5001
4982
4983
+ GET_REFLECTION_OBJECT_PTR (ce );
4984
+
5002
4985
RETURN_BOOL ((ce != class_ce && instanceof_function (ce , class_ce )));
5003
4986
}
5004
4987
/* }}} */
@@ -5007,44 +4990,36 @@ ZEND_METHOD(ReflectionClass, isSubclassOf)
5007
4990
ZEND_METHOD (ReflectionClass , implementsInterface )
5008
4991
{
5009
4992
reflection_object * intern , * argument ;
4993
+ zend_string * interface_str ;
5010
4994
zend_class_entry * ce , * interface_ce ;
5011
- zval * interface ;
4995
+ zend_object * interface_obj ;
5012
4996
5013
- GET_REFLECTION_OBJECT_PTR (ce );
4997
+ ZEND_PARSE_PARAMETERS_START (1 , 1 )
4998
+ Z_PARAM_STR_OR_OBJ_OF_CLASS (interface_str , interface_obj , reflection_class_ptr )
4999
+ ZEND_PARSE_PARAMETERS_END ();
5014
5000
5015
- if (zend_parse_parameters (ZEND_NUM_ARGS (), "z" , & interface ) == FAILURE ) {
5016
- RETURN_THROWS ();
5017
- }
5001
+ if (interface_obj ) {
5002
+ argument = reflection_object_from_obj (interface_obj );
5003
+ if (argument -> ptr == NULL ) {
5004
+ zend_throw_error (NULL , "Internal error: Failed to retrieve the argument's reflection object" );
5005
+ RETURN_THROWS ();
5006
+ }
5018
5007
5019
- switch (Z_TYPE_P (interface )) {
5020
- case IS_STRING :
5021
- if ((interface_ce = zend_lookup_class (Z_STR_P (interface ))) == NULL ) {
5022
- zend_throw_exception_ex (reflection_exception_ptr , 0 ,
5023
- "Interface \"%s\" does not exist" , Z_STRVAL_P (interface ));
5024
- RETURN_THROWS ();
5025
- }
5026
- break ;
5027
- case IS_OBJECT :
5028
- if (instanceof_function (Z_OBJCE_P (interface ), reflection_class_ptr )) {
5029
- argument = Z_REFLECTION_P (interface );
5030
- if (argument -> ptr == NULL ) {
5031
- zend_throw_error (NULL , "Internal error: Failed to retrieve the argument's reflection object" );
5032
- RETURN_THROWS ();
5033
- }
5034
- interface_ce = argument -> ptr ;
5035
- break ;
5036
- }
5037
- /* no break */
5038
- default :
5039
- zend_argument_error (reflection_exception_ptr , 1 , "must be of type ReflectionClass|string, %s given" , zend_zval_type_name (interface ));
5008
+ interface_ce = argument -> ptr ;
5009
+ } else {
5010
+ if ((interface_ce = zend_lookup_class (interface_str )) == NULL ) {
5011
+ zend_throw_exception_ex (reflection_exception_ptr , 0 , "Interface \"%s\" does not exist" , ZSTR_VAL (interface_str ));
5040
5012
RETURN_THROWS ();
5013
+ }
5041
5014
}
5042
5015
5043
5016
if (!(interface_ce -> ce_flags & ZEND_ACC_INTERFACE )) {
5044
- zend_throw_exception_ex (reflection_exception_ptr , 0 ,
5045
- "%s is not an interface" , ZSTR_VAL (interface_ce -> name ));
5017
+ zend_throw_exception_ex (reflection_exception_ptr , 0 , "%s is not an interface" , ZSTR_VAL (interface_ce -> name ));
5046
5018
RETURN_THROWS ();
5047
5019
}
5020
+
5021
+ GET_REFLECTION_OBJECT_PTR (ce );
5022
+
5048
5023
RETURN_BOOL (instanceof_function (ce , interface_ce ));
5049
5024
}
5050
5025
/* }}} */
@@ -5178,7 +5153,8 @@ ZEND_METHOD(ReflectionObject, __construct)
5178
5153
/* {{{ Constructor. Throws an Exception in case the given property does not exist */
5179
5154
ZEND_METHOD (ReflectionProperty , __construct )
5180
5155
{
5181
- zval * classname ;
5156
+ zend_string * classname_str ;
5157
+ zend_object * classname_obj ;
5182
5158
zend_string * name ;
5183
5159
int dynam_prop = 0 ;
5184
5160
zval * object ;
@@ -5187,39 +5163,30 @@ ZEND_METHOD(ReflectionProperty, __construct)
5187
5163
zend_property_info * property_info = NULL ;
5188
5164
property_reference * reference ;
5189
5165
5190
- if (zend_parse_parameters (ZEND_NUM_ARGS (), "zS" , & classname , & name ) == FAILURE ) {
5191
- RETURN_THROWS ();
5192
- }
5166
+ ZEND_PARSE_PARAMETERS_START (2 , 2 )
5167
+ Z_PARAM_STR_OR_OBJ (classname_str , classname_obj )
5168
+ Z_PARAM_STR (name )
5169
+ ZEND_PARSE_PARAMETERS_END ();
5193
5170
5194
5171
object = ZEND_THIS ;
5195
5172
intern = Z_REFLECTION_P (object );
5196
5173
5197
- /* Find the class entry */
5198
- switch (Z_TYPE_P (classname )) {
5199
- case IS_STRING :
5200
- if ((ce = zend_lookup_class (Z_STR_P (classname ))) == NULL ) {
5201
- zend_throw_exception_ex (reflection_exception_ptr , 0 ,
5202
- "Class \"%s\" does not exist" , Z_STRVAL_P (classname ));
5203
- RETURN_THROWS ();
5204
- }
5205
- break ;
5206
-
5207
- case IS_OBJECT :
5208
- ce = Z_OBJCE_P (classname );
5209
- break ;
5210
-
5211
- default :
5212
- zend_argument_error (reflection_exception_ptr , 1 , "must be of type object|string, %s given" , zend_zval_type_name (classname ));
5174
+ if (classname_obj ) {
5175
+ ce = classname_obj -> ce ;
5176
+ } else {
5177
+ if ((ce = zend_lookup_class (classname_str )) == NULL ) {
5178
+ zend_throw_exception_ex (reflection_exception_ptr , 0 , "Class \"%s\" does not exist" , ZSTR_VAL (classname_str ));
5213
5179
RETURN_THROWS ();
5180
+ }
5214
5181
}
5215
5182
5216
5183
property_info = zend_hash_find_ptr (& ce -> properties_info , name );
5217
5184
if (property_info == NULL
5218
5185
|| ((property_info -> flags & ZEND_ACC_PRIVATE )
5219
5186
&& property_info -> ce != ce )) {
5220
5187
/* Check for dynamic properties */
5221
- if (property_info == NULL && Z_TYPE_P ( classname ) == IS_OBJECT ) {
5222
- if (zend_hash_exists (Z_OBJ_HT_P ( classname ) -> get_properties (Z_OBJ_P ( classname ) ), name )) {
5188
+ if (property_info == NULL && classname_obj ) {
5189
+ if (zend_hash_exists (classname_obj -> handlers -> get_properties (classname_obj ), name )) {
5223
5190
dynam_prop = 1 ;
5224
5191
}
5225
5192
}
0 commit comments