@@ -1219,6 +1219,8 @@ static zend_always_inline zval *zend_try_array_init(zval *zv)
1219
1219
_(Z_EXPECTED_STRING_OR_LONG_OR_NULL, "of type string|int|null") \
1220
1220
_(Z_EXPECTED_CLASS_NAME_OR_OBJECT, "a valid class name or object") \
1221
1221
_(Z_EXPECTED_CLASS_NAME_OR_OBJECT_OR_NULL, "a valid class name, object, or null") \
1222
+ _(Z_EXPECTED_STRING_OR_OBJECT, "of type object|string") \
1223
+ _(Z_EXPECTED_STRING_OR_OBJECT_OR_NULL, "of type object|string|null") \
1222
1224
1223
1225
#define Z_EXPECTED_TYPE
1224
1226
@@ -1235,18 +1237,22 @@ ZEND_API ZEND_COLD void ZEND_FASTCALL zend_wrong_parameters_count_error(int min_
1235
1237
ZEND_API ZEND_COLD void ZEND_FASTCALL zend_wrong_parameter_type_error (int num , zend_expected_type expected_type , zval * arg );
1236
1238
ZEND_API ZEND_COLD void ZEND_FASTCALL zend_wrong_parameter_class_error (int num , const char * name , zval * arg );
1237
1239
ZEND_API ZEND_COLD void ZEND_FASTCALL zend_wrong_parameter_class_or_null_error (int num , const char * name , zval * arg );
1240
+ ZEND_API ZEND_COLD void ZEND_FASTCALL zend_wrong_parameter_string_or_class_error (int num , const char * name , zval * arg );
1241
+ ZEND_API ZEND_COLD void ZEND_FASTCALL zend_wrong_parameter_string_or_class_or_null_error (int num , const char * name , zval * arg );
1238
1242
ZEND_API ZEND_COLD void ZEND_FASTCALL zend_wrong_callback_error (int num , char * error );
1239
1243
ZEND_API ZEND_COLD void ZEND_FASTCALL zend_argument_error (zend_class_entry * error_ce , uint32_t arg_num , const char * format , ...);
1240
1244
ZEND_API ZEND_COLD void ZEND_FASTCALL zend_argument_type_error (uint32_t arg_num , const char * format , ...);
1241
1245
ZEND_API ZEND_COLD void ZEND_FASTCALL zend_argument_value_error (uint32_t arg_num , const char * format , ...);
1242
1246
1243
- #define ZPP_ERROR_OK 0
1244
- #define ZPP_ERROR_FAILURE 1
1245
- #define ZPP_ERROR_WRONG_CALLBACK 2
1246
- #define ZPP_ERROR_WRONG_CLASS 3
1247
- #define ZPP_ERROR_WRONG_CLASS_OR_NULL 4
1248
- #define ZPP_ERROR_WRONG_ARG 5
1249
- #define ZPP_ERROR_WRONG_COUNT 6
1247
+ #define ZPP_ERROR_OK 0
1248
+ #define ZPP_ERROR_FAILURE 1
1249
+ #define ZPP_ERROR_WRONG_CALLBACK 2
1250
+ #define ZPP_ERROR_WRONG_CLASS 3
1251
+ #define ZPP_ERROR_WRONG_CLASS_OR_NULL 4
1252
+ #define ZPP_ERROR_WRONG_ARG 5
1253
+ #define ZPP_ERROR_WRONG_COUNT 6
1254
+ #define ZPP_ERROR_WRONG_STRING_OR_CLASS 7
1255
+ #define ZPP_ERROR_WRONG_STRING_OR_CLASS_OR_NULL 8
1250
1256
1251
1257
#define ZEND_PARSE_PARAMETERS_START_EX (flags , min_num_args , max_num_args ) do { \
1252
1258
const int _flags = (flags); \
@@ -1301,6 +1307,10 @@ ZEND_API ZEND_COLD void ZEND_FASTCALL zend_argument_value_error(uint32_t arg_num
1301
1307
zend_wrong_parameter_class_or_null_error(_i, _error, _arg); \
1302
1308
} else if (_error_code == ZPP_ERROR_WRONG_ARG) { \
1303
1309
zend_wrong_parameter_type_error(_i, _expected_type, _arg); \
1310
+ } else if (_error_code == ZPP_ERROR_WRONG_STRING_OR_CLASS) { \
1311
+ zend_wrong_parameter_string_or_class_error(_i, _error, _arg); \
1312
+ } else if (_error_code == ZPP_ERROR_WRONG_STRING_OR_CLASS_OR_NULL) { \
1313
+ zend_wrong_parameter_string_or_class_or_null_error(_i, _error, _arg); \
1304
1314
} \
1305
1315
} \
1306
1316
failure; \
@@ -1411,6 +1421,40 @@ ZEND_API ZEND_COLD void ZEND_FASTCALL zend_argument_value_error(uint32_t arg_num
1411
1421
#define Z_PARAM_CLASS_NAME_OR_OBJ_OR_NULL (dest ) \
1412
1422
Z_PARAM_CLASS_NAME_OR_OBJ_EX(dest, 1);
1413
1423
1424
+ #define Z_PARAM_STR_OR_OBJ_EX (destination_string , destination_object , allow_null ) \
1425
+ Z_PARAM_PROLOGUE(0, 0); \
1426
+ if (UNEXPECTED(!zend_parse_arg_str_or_obj(_arg, &destination_string, &destination_object, NULL, allow_null))) { \
1427
+ _expected_type = allow_null ? Z_EXPECTED_STRING_OR_OBJECT_OR_NULL : Z_EXPECTED_STRING_OR_OBJECT; \
1428
+ _error_code = ZPP_ERROR_WRONG_ARG; \
1429
+ break; \
1430
+ }
1431
+
1432
+ #define Z_PARAM_STR_OR_OBJ (destination_string , destination_object ) \
1433
+ Z_PARAM_STR_OR_OBJ_EX(destination_string, destination_object, 0);
1434
+
1435
+ #define Z_PARAM_STR_OR_OBJ_OR_NULL (destination_string , destination_object ) \
1436
+ Z_PARAM_STR_OR_OBJ_EX(destination_string, destination_object, 1);
1437
+
1438
+ #define Z_PARAM_STR_OR_OBJ_OF_CLASS_EX (destination_string , destination_object , base_ce , allow_null ) \
1439
+ Z_PARAM_PROLOGUE(0, 0); \
1440
+ if (UNEXPECTED(!zend_parse_arg_str_or_obj(_arg, &destination_string, &destination_object, base_ce, allow_null))) { \
1441
+ if (base_ce) { \
1442
+ _error = ZSTR_VAL((base_ce)->name); \
1443
+ _error_code = allow_null ? ZPP_ERROR_WRONG_STRING_OR_CLASS_OR_NULL : ZPP_ERROR_WRONG_STRING_OR_CLASS; \
1444
+ break; \
1445
+ } else { \
1446
+ _expected_type = allow_null ? Z_EXPECTED_STRING_OR_OBJECT_OR_NULL : Z_EXPECTED_STRING_OR_OBJECT; \
1447
+ _error_code = ZPP_ERROR_WRONG_ARG; \
1448
+ break; \
1449
+ } \
1450
+ }
1451
+
1452
+ #define Z_PARAM_STR_OR_OBJ_OF_CLASS (destination_string , destination_object , base_ce ) \
1453
+ Z_PARAM_STR_OR_OBJ_OF_CLASS_EX(destination_string, destination_object, base_ce, 0);
1454
+
1455
+ #define Z_PARAM_STR_OR_OBJ_OF_CLASS_OR_NULL (destination_string , destination_object , base_ce ) \
1456
+ Z_PARAM_STR_OR_OBJ_OF_CLASS_EX(destination_string, destination_object, base_ce, 1);
1457
+
1414
1458
/* old "d" */
1415
1459
#define Z_PARAM_DOUBLE_EX2 (dest , is_null , check_null , deref , separate ) \
1416
1460
Z_PARAM_PROLOGUE(deref, separate); \
@@ -1972,6 +2016,30 @@ static zend_always_inline int zend_parse_arg_class_name_or_obj(
1972
2016
return 1 ;
1973
2017
}
1974
2018
2019
+ static zend_always_inline int zend_parse_arg_str_or_obj (
2020
+ zval * arg , zend_string * * destination_string , zend_object * * destination_object , zend_class_entry * base_ce , int allow_null
2021
+ ) {
2022
+ if (EXPECTED (Z_TYPE_P (arg ) == IS_OBJECT )) {
2023
+ if (base_ce && UNEXPECTED (!instanceof_function (Z_OBJCE_P (arg ), base_ce ))) {
2024
+ return 0 ;
2025
+ }
2026
+
2027
+ * destination_string = NULL ;
2028
+ * destination_object = Z_OBJ_P (arg );
2029
+ } else if (EXPECTED (Z_TYPE_P (arg ) == IS_STRING )) {
2030
+ * destination_string = Z_STR_P (arg );
2031
+ * destination_object = NULL ;
2032
+ } else if (allow_null && EXPECTED (Z_TYPE_P (arg ) == IS_NULL )) {
2033
+ * destination_string = NULL ;
2034
+ * destination_object = NULL ;
2035
+ } else {
2036
+ * destination_object = NULL ;
2037
+ return zend_parse_arg_str_slow (arg , destination_string );
2038
+ }
2039
+
2040
+ return 1 ;
2041
+ }
2042
+
1975
2043
END_EXTERN_C ()
1976
2044
1977
2045
#endif /* ZEND_API_H */
0 commit comments