@@ -1055,7 +1055,7 @@ static void reflection_attribute_factory(zval *object, zend_string *name, zval *
1055
1055
}
1056
1056
/* }}} */
1057
1057
1058
- static int convert_ast_to_zval (zval * ret , zend_ast * ast , zend_class_entry * scope_ce )
1058
+ static int convert_ast_to_zval (zval * ret , zend_ast * ast , zend_class_entry * scope_ce ) /* {{{ */
1059
1059
{
1060
1060
if (ast -> kind == ZEND_AST_CONSTANT ) {
1061
1061
zend_string * name = zend_ast_get_constant_name (ast );
@@ -1079,8 +1079,9 @@ static int convert_ast_to_zval(zval *ret, zend_ast *ast, zend_class_entry *scope
1079
1079
1080
1080
return SUCCESS ;
1081
1081
}
1082
+ /* }}} */
1082
1083
1083
- static int convert_ast_attributes (zval * ret , HashTable * attributes , zend_class_entry * scope_ce )
1084
+ static int convert_ast_attributes (zval * ret , HashTable * attributes , zend_class_entry * scope_ce ) /* {{{ */
1084
1085
{
1085
1086
Bucket * p ;
1086
1087
zval tmp ;
@@ -1106,8 +1107,9 @@ static int convert_ast_attributes(zval *ret, HashTable *attributes, zend_class_e
1106
1107
1107
1108
return SUCCESS ;
1108
1109
}
1110
+ /* }}} */
1109
1111
1110
- static int load_attributes (zval * ret , HashTable * attr , zend_class_entry * scope )
1112
+ static int load_attributes (zval * ret , HashTable * attr , zend_class_entry * scope ) /* {{{ */
1111
1113
{
1112
1114
zval obj ;
1113
1115
zval result ;
@@ -1144,9 +1146,10 @@ static int load_attributes(zval *ret, HashTable *attr, zend_class_entry *scope)
1144
1146
1145
1147
return SUCCESS ;
1146
1148
}
1149
+ /* }}} */
1147
1150
1148
1151
static int convert_attributes (zval * ret , HashTable * attributes , zend_class_entry * scope ,
1149
- zend_string * name , zend_class_entry * base )
1152
+ zend_string * name , zend_class_entry * base ) /* {{{ */
1150
1153
{
1151
1154
Bucket * p ;
1152
1155
@@ -1167,7 +1170,7 @@ static int convert_attributes(zval *ret, HashTable *attributes, zend_class_entry
1167
1170
} else {
1168
1171
ZEND_HASH_FOREACH_BUCKET (attributes , p ) {
1169
1172
if (!p -> key ) {
1170
- // Skip inlined parameter annotations .
1173
+ // Skip inlined parameter attributes .
1171
1174
continue ;
1172
1175
}
1173
1176
@@ -1205,6 +1208,43 @@ static int convert_attributes(zval *ret, HashTable *attributes, zend_class_entry
1205
1208
1206
1209
return SUCCESS ;
1207
1210
}
1211
+ /* }}} */
1212
+
1213
+ static void reflect_attributes (INTERNAL_FUNCTION_PARAMETERS , HashTable * attributes , zend_class_entry * scope ) /* {{{ */
1214
+ {
1215
+ zval ret ;
1216
+
1217
+ zend_string * name = NULL ;
1218
+ zend_bool inherited = 0 ;
1219
+ zend_class_entry * base = NULL ;
1220
+
1221
+ if (zend_parse_parameters (ZEND_NUM_ARGS (), "|Sb" , & name , & inherited ) == FAILURE ) {
1222
+ RETURN_THROWS ();
1223
+ }
1224
+
1225
+ if (name && inherited ) {
1226
+ if (NULL == (base = zend_lookup_class (name ))) {
1227
+ if (!EG (exception )) {
1228
+ zend_throw_error (NULL , "Class '%s' not found" , ZSTR_VAL (name ));
1229
+ }
1230
+
1231
+ RETURN_THROWS ();
1232
+ }
1233
+
1234
+ name = NULL ;
1235
+ }
1236
+
1237
+ if (!attributes ) {
1238
+ RETURN_EMPTY_ARRAY ();
1239
+ }
1240
+
1241
+ if (FAILURE == convert_attributes (& ret , attributes , scope , name , base )) {
1242
+ RETURN_THROWS ();
1243
+ }
1244
+
1245
+ RETURN_ZVAL (& ret , 1 , 1 );
1246
+ }
1247
+ /* }}} */
1208
1248
1209
1249
static void _zend_extension_string (smart_str * str , zend_extension * extension , char * indent ) /* {{{ */
1210
1250
{
@@ -1818,39 +1858,17 @@ ZEND_METHOD(reflection_function, getAttributes)
1818
1858
reflection_object * intern ;
1819
1859
zend_function * fptr ;
1820
1860
1821
- zend_string * name = NULL ;
1822
- zend_bool inherited = 0 ;
1823
- zend_class_entry * base = NULL ;
1824
-
1825
- if (zend_parse_parameters (ZEND_NUM_ARGS (), "|Sb" , & name , & inherited ) == FAILURE ) {
1826
- RETURN_THROWS ();
1827
- }
1828
-
1829
- if (name && inherited ) {
1830
- if (NULL == (base = zend_lookup_class (name ))) {
1831
- if (!EG (exception )) {
1832
- zend_throw_error (NULL , "Class '%s' not found" , ZSTR_VAL (name ));
1833
- }
1834
-
1835
- RETURN_THROWS ();
1836
- }
1837
-
1838
- name = NULL ;
1839
- }
1861
+ HashTable * attributes = NULL ;
1862
+ zend_class_entry * scope = NULL ;
1840
1863
1841
1864
GET_REFLECTION_OBJECT_PTR (fptr );
1842
1865
1843
1866
if (fptr -> type == ZEND_USER_FUNCTION && fptr -> op_array .attributes ) {
1844
- zval ret ;
1845
-
1846
- if (FAILURE == convert_attributes (& ret , fptr -> op_array .attributes , fptr -> common .scope , name , base )) {
1847
- RETURN_THROWS ();
1848
- }
1849
-
1850
- RETURN_ZVAL (& ret , 1 , 1 );
1867
+ attributes = fptr -> op_array .attributes ;
1868
+ scope = fptr -> common .scope ;
1851
1869
}
1852
1870
1853
- RETURN_EMPTY_ARRAY ( );
1871
+ reflect_attributes ( INTERNAL_FUNCTION_PARAM_PASSTHRU , attributes , scope );
1854
1872
}
1855
1873
/* }}} */
1856
1874
@@ -2783,45 +2801,23 @@ ZEND_METHOD(reflection_parameter, getAttributes)
2783
2801
reflection_object * intern ;
2784
2802
parameter_reference * param ;
2785
2803
2786
- zend_string * name = NULL ;
2787
- zend_bool inherited = 0 ;
2788
- zend_class_entry * base = NULL ;
2789
-
2790
- if (zend_parse_parameters (ZEND_NUM_ARGS (), "|Sb" , & name , & inherited ) == FAILURE ) {
2791
- RETURN_THROWS ();
2792
- }
2793
-
2794
- if (name && inherited ) {
2795
- if (NULL == (base = zend_lookup_class (name ))) {
2796
- if (!EG (exception )) {
2797
- zend_throw_error (NULL , "Class '%s' not found" , ZSTR_VAL (name ));
2798
- }
2799
-
2800
- RETURN_THROWS ();
2801
- }
2802
-
2803
- name = NULL ;
2804
- }
2804
+ HashTable * attributes = NULL ;
2805
+ zend_class_entry * scope = NULL ;
2805
2806
2806
2807
GET_REFLECTION_OBJECT_PTR (param );
2807
2808
2808
2809
if (param -> fptr -> type == ZEND_USER_FUNCTION && param -> fptr -> op_array .attributes ) {
2809
2810
zval * attr ;
2810
2811
2811
2812
if (NULL != (attr = zend_hash_index_find (param -> fptr -> op_array .attributes , param -> offset ))) {
2812
- zval ret ;
2813
-
2814
2813
ZEND_ASSERT (Z_TYPE_P (attr ) == IS_ARRAY );
2815
2814
2816
- if (FAILURE == convert_attributes (& ret , Z_ARRVAL_P (attr ), param -> fptr -> common .scope , name , base )) {
2817
- RETURN_THROWS ();
2818
- }
2819
-
2820
- RETURN_ZVAL (& ret , 1 , 1 );
2815
+ attributes = Z_ARRVAL_P (attr );
2816
+ scope = param -> fptr -> common .scope ;
2821
2817
}
2822
2818
}
2823
2819
2824
- RETURN_EMPTY_ARRAY ( );
2820
+ reflect_attributes ( INTERNAL_FUNCTION_PARAM_PASSTHRU , attributes , scope );
2825
2821
}
2826
2822
2827
2823
/* {{{ proto public bool ReflectionParameter::getPosition()
@@ -3893,39 +3889,17 @@ ZEND_METHOD(reflection_class_constant, getAttributes)
3893
3889
reflection_object * intern ;
3894
3890
zend_class_constant * ref ;
3895
3891
3896
- zend_string * name = NULL ;
3897
- zend_bool inherited = 0 ;
3898
- zend_class_entry * base = NULL ;
3899
-
3900
- if (zend_parse_parameters (ZEND_NUM_ARGS (), "|Sb" , & name , & inherited ) == FAILURE ) {
3901
- RETURN_THROWS ();
3902
- }
3903
-
3904
- if (name && inherited ) {
3905
- if (NULL == (base = zend_lookup_class (name ))) {
3906
- if (!EG (exception )) {
3907
- zend_throw_error (NULL , "Class '%s' not found" , ZSTR_VAL (name ));
3908
- }
3909
-
3910
- RETURN_THROWS ();
3911
- }
3912
-
3913
- name = NULL ;
3914
- }
3892
+ HashTable * attributes = NULL ;
3893
+ zend_class_entry * scope = NULL ;
3915
3894
3916
3895
GET_REFLECTION_OBJECT_PTR (ref );
3917
3896
3918
3897
if (ref -> attributes ) {
3919
- zval ret ;
3920
-
3921
- if (FAILURE == convert_attributes (& ret , ref -> attributes , ref -> ce , name , base )) {
3922
- RETURN_THROWS ();
3923
- }
3924
-
3925
- RETURN_ZVAL (& ret , 1 , 1 );
3898
+ attributes = ref -> attributes ;
3899
+ scope = ref -> ce ;
3926
3900
}
3927
3901
3928
- RETURN_EMPTY_ARRAY ( );
3902
+ reflect_attributes ( INTERNAL_FUNCTION_PARAM_PASSTHRU , attributes , scope );
3929
3903
}
3930
3904
/* }}} */
3931
3905
@@ -4298,39 +4272,17 @@ ZEND_METHOD(reflection_class, getAttributes)
4298
4272
reflection_object * intern ;
4299
4273
zend_class_entry * ce ;
4300
4274
4301
- zend_string * name = NULL ;
4302
- zend_bool inherited = 0 ;
4303
- zend_class_entry * base = NULL ;
4304
-
4305
- if (zend_parse_parameters (ZEND_NUM_ARGS (), "|Sb" , & name , & inherited ) == FAILURE ) {
4306
- RETURN_THROWS ();
4307
- }
4308
-
4309
- if (name && inherited ) {
4310
- if (NULL == (base = zend_lookup_class (name ))) {
4311
- if (!EG (exception )) {
4312
- zend_throw_error (NULL , "Class '%s' not found" , ZSTR_VAL (name ));
4313
- }
4314
-
4315
- RETURN_THROWS ();
4316
- }
4317
-
4318
- name = NULL ;
4319
- }
4275
+ HashTable * attributes = NULL ;
4276
+ zend_class_entry * scope = NULL ;
4320
4277
4321
4278
GET_REFLECTION_OBJECT_PTR (ce );
4322
4279
4323
4280
if (ce -> type == ZEND_USER_CLASS && ce -> info .user .attributes ) {
4324
- zval ret ;
4325
-
4326
- if (FAILURE == convert_attributes (& ret , ce -> info .user .attributes , ce , name , base )) {
4327
- RETURN_THROWS ();
4328
- }
4329
-
4330
- RETURN_ZVAL (& ret , 1 , 1 );
4281
+ attributes = ce -> info .user .attributes ;
4282
+ scope = ce ;
4331
4283
}
4332
4284
4333
- RETURN_EMPTY_ARRAY ( );
4285
+ reflect_attributes ( INTERNAL_FUNCTION_PARAM_PASSTHRU , attributes , scope );
4334
4286
}
4335
4287
/* }}} */
4336
4288
@@ -5844,39 +5796,17 @@ ZEND_METHOD(reflection_property, getAttributes)
5844
5796
reflection_object * intern ;
5845
5797
property_reference * ref ;
5846
5798
5847
- zend_string * name = NULL ;
5848
- zend_bool inherited = 0 ;
5849
- zend_class_entry * base = NULL ;
5850
-
5851
- if (zend_parse_parameters (ZEND_NUM_ARGS (), "|Sb" , & name , & inherited ) == FAILURE ) {
5852
- RETURN_THROWS ();
5853
- }
5854
-
5855
- if (name && inherited ) {
5856
- if (NULL == (base = zend_lookup_class (name ))) {
5857
- if (!EG (exception )) {
5858
- zend_throw_error (NULL , "Class '%s' not found" , ZSTR_VAL (name ));
5859
- }
5860
-
5861
- RETURN_THROWS ();
5862
- }
5863
-
5864
- name = NULL ;
5865
- }
5799
+ HashTable * attributes = NULL ;
5800
+ zend_class_entry * scope = NULL ;
5866
5801
5867
5802
GET_REFLECTION_OBJECT_PTR (ref );
5868
5803
5869
5804
if (ref -> prop -> attributes ) {
5870
- zval ret ;
5871
-
5872
- if (FAILURE == convert_attributes (& ret , ref -> prop -> attributes , ref -> prop -> ce , name , base )) {
5873
- RETURN_THROWS ();
5874
- }
5875
-
5876
- RETURN_ZVAL (& ret , 1 , 1 );
5805
+ attributes = ref -> prop -> attributes ;
5806
+ scope = ref -> prop -> ce ;
5877
5807
}
5878
5808
5879
- RETURN_EMPTY_ARRAY ( );
5809
+ reflect_attributes ( INTERNAL_FUNCTION_PARAM_PASSTHRU , attributes , scope );
5880
5810
}
5881
5811
/* }}} */
5882
5812
@@ -6756,7 +6686,7 @@ ZEND_METHOD(reflection_attribute, getAsObject)
6756
6686
}
6757
6687
} else if (argc ) {
6758
6688
attribute_ctor_cleanup (& obj , args , argc );
6759
- zend_throw_error (NULL , "Annotation class '%s' does not have a constructor, cannot pass arguments" , ZSTR_VAL (ce -> name ));
6689
+ zend_throw_error (NULL , "Attribute class '%s' does not have a constructor, cannot pass arguments" , ZSTR_VAL (ce -> name ));
6760
6690
RETURN_THROWS ();
6761
6691
}
6762
6692
0 commit comments