@@ -1209,6 +1209,8 @@ static zend_always_inline zval *zend_try_array_init(zval *zv)
1209
1209
_(Z_EXPECTED_STRING_OR_NULL, "of type ?string") \
1210
1210
_(Z_EXPECTED_ARRAY, "of type array") \
1211
1211
_(Z_EXPECTED_ARRAY_OR_NULL, "of type ?array") \
1212
+ _(Z_EXPECTED_ARRAY_OR_LONG, "of type array|int") \
1213
+ _(Z_EXPECTED_ARRAY_OR_LONG_OR_NULL, "of type array|int|null") \
1212
1214
_(Z_EXPECTED_ITERABLE, "of type iterable") \
1213
1215
_(Z_EXPECTED_ITERABLE_OR_NULL, "of type ?iterable") \
1214
1216
_(Z_EXPECTED_FUNC, "a valid callback") \
@@ -1248,6 +1250,8 @@ ZEND_API ZEND_COLD void ZEND_FASTCALL zend_wrong_parameter_error(int error_code,
1248
1250
ZEND_API ZEND_COLD void ZEND_FASTCALL zend_wrong_parameter_type_error (uint32_t num , zend_expected_type expected_type , zval * arg );
1249
1251
ZEND_API ZEND_COLD void ZEND_FASTCALL zend_wrong_parameter_class_error (uint32_t num , const char * name , zval * arg );
1250
1252
ZEND_API ZEND_COLD void ZEND_FASTCALL zend_wrong_parameter_class_or_null_error (uint32_t num , const char * name , zval * arg );
1253
+ ZEND_API ZEND_COLD void ZEND_FASTCALL zend_wrong_parameter_class_or_long_error (uint32_t num , const char * name , zval * arg );
1254
+ ZEND_API ZEND_COLD void ZEND_FASTCALL zend_wrong_parameter_class_or_long_or_null_error (uint32_t num , const char * name , zval * arg );
1251
1255
ZEND_API ZEND_COLD void ZEND_FASTCALL zend_wrong_parameter_string_or_class_error (uint32_t num , const char * name , zval * arg );
1252
1256
ZEND_API ZEND_COLD void ZEND_FASTCALL zend_wrong_parameter_string_or_class_or_null_error (uint32_t num , const char * name , zval * arg );
1253
1257
ZEND_API ZEND_COLD void ZEND_FASTCALL zend_wrong_callback_error (uint32_t num , char * error );
@@ -1261,11 +1265,13 @@ ZEND_API ZEND_COLD void zend_argument_value_error(uint32_t arg_num, const char *
1261
1265
#define ZPP_ERROR_WRONG_CALLBACK 2
1262
1266
#define ZPP_ERROR_WRONG_CLASS 3
1263
1267
#define ZPP_ERROR_WRONG_CLASS_OR_NULL 4
1264
- #define ZPP_ERROR_WRONG_ARG 5
1265
- #define ZPP_ERROR_WRONG_COUNT 6
1266
- #define ZPP_ERROR_WRONG_STRING_OR_CLASS 7
1267
- #define ZPP_ERROR_WRONG_STRING_OR_CLASS_OR_NULL 8
1268
- #define ZPP_ERROR_UNEXPECTED_EXTRA_NAMED 9
1268
+ #define ZPP_ERROR_WRONG_CLASS_OR_LONG 5
1269
+ #define ZPP_ERROR_WRONG_CLASS_OR_LONG_OR_NULL 6
1270
+ #define ZPP_ERROR_WRONG_ARG 7
1271
+ #define ZPP_ERROR_WRONG_COUNT 8
1272
+ #define ZPP_ERROR_WRONG_STRING_OR_CLASS 9
1273
+ #define ZPP_ERROR_WRONG_STRING_OR_CLASS_OR_NULL 10
1274
+ #define ZPP_ERROR_UNEXPECTED_EXTRA_NAMED 11
1269
1275
1270
1276
#define ZEND_PARSE_PARAMETERS_START_EX (flags , min_num_args , max_num_args ) do { \
1271
1277
const int _flags = (flags); \
@@ -1530,6 +1536,20 @@ ZEND_API ZEND_COLD void zend_argument_value_error(uint32_t arg_num, const char *
1530
1536
#define Z_PARAM_ARRAY_HT_OR_NULL (dest ) \
1531
1537
Z_PARAM_ARRAY_HT_EX(dest, 1, 0)
1532
1538
1539
+ #define Z_PARAM_ARRAY_HT_OR_LONG_EX (dest_ht , dest_long , is_null , allow_null ) \
1540
+ Z_PARAM_PROLOGUE(0, 0); \
1541
+ if (UNEXPECTED(!zend_parse_arg_array_ht_or_long(_arg, &dest_ht, &dest_long, &is_null, allow_null))) { \
1542
+ _expected_type = allow_null ? Z_EXPECTED_ARRAY_OR_LONG_OR_NULL : Z_EXPECTED_ARRAY_OR_LONG; \
1543
+ _error_code = ZPP_ERROR_WRONG_ARG; \
1544
+ break; \
1545
+ }
1546
+
1547
+ #define Z_PARAM_ARRAY_HT_OR_LONG (dest_ht , dest_long ) \
1548
+ Z_PARAM_ARRAY_HT_OR_LONG_EX(dest_ht, dest_long, _dummy, 0)
1549
+
1550
+ #define Z_PARAM_ARRAY_HT_OR_LONG_OR_NULL (dest_ht , dest_long , is_null ) \
1551
+ Z_PARAM_ARRAY_HT_OR_LONG_EX(dest_ht, dest_long, is_null, 1)
1552
+
1533
1553
/* old "H" */
1534
1554
#define Z_PARAM_ARRAY_OR_OBJECT_HT_EX2 (dest , check_null , deref , separate ) \
1535
1555
Z_PARAM_PROLOGUE(deref, separate); \
@@ -1638,6 +1658,44 @@ ZEND_API ZEND_COLD void zend_argument_value_error(uint32_t arg_num, const char *
1638
1658
#define Z_PARAM_OBJECT_OF_CLASS_OR_NULL (dest , _ce ) \
1639
1659
Z_PARAM_OBJECT_OF_CLASS_EX(dest, _ce, 1, 0)
1640
1660
1661
+ /* The same as Z_PARAM_OBJECT_OF_CLASS_EX2 except that dest is a zend_object rather than a zval */
1662
+ #define Z_PARAM_OBJ_OF_CLASS_EX2 (dest , _ce , check_null , deref , separate ) \
1663
+ Z_PARAM_PROLOGUE(deref, separate); \
1664
+ if (UNEXPECTED(!zend_parse_arg_obj(_arg, &dest, _ce, check_null))) { \
1665
+ if (_ce) { \
1666
+ _error = ZSTR_VAL((_ce)->name); \
1667
+ _error_code = check_null ? ZPP_ERROR_WRONG_CLASS_OR_NULL : ZPP_ERROR_WRONG_CLASS; \
1668
+ break; \
1669
+ } else { \
1670
+ _expected_type = check_null ? Z_EXPECTED_OBJECT_OR_NULL : Z_EXPECTED_OBJECT; \
1671
+ _error_code = ZPP_ERROR_WRONG_ARG; \
1672
+ break; \
1673
+ } \
1674
+ }
1675
+
1676
+ #define Z_PARAM_OBJ_OF_CLASS_EX (dest , _ce , check_null , separate ) \
1677
+ Z_PARAM_OBJ_OF_CLASS_EX2(dest, _ce, check_null, separate, separate)
1678
+
1679
+ #define Z_PARAM_OBJ_OF_CLASS (dest , _ce ) \
1680
+ Z_PARAM_OBJ_OF_CLASS_EX(dest, _ce, 0, 0)
1681
+
1682
+ #define Z_PARAM_OBJ_OF_CLASS_OR_NULL (dest , _ce ) \
1683
+ Z_PARAM_OBJ_OF_CLASS_EX(dest, _ce, 1, 0)
1684
+
1685
+ #define Z_PARAM_OBJ_OF_CLASS_OR_LONG_EX (dest_obj , _ce , dest_long , is_null , allow_null ) \
1686
+ Z_PARAM_PROLOGUE(0, 0); \
1687
+ if (UNEXPECTED(!zend_parse_arg_obj_or_long(_arg, &dest_obj, _ce, &dest_long, &is_null, allow_null))) { \
1688
+ _error = ZSTR_VAL((_ce)->name); \
1689
+ _error_code = allow_null ? ZPP_ERROR_WRONG_CLASS_OR_LONG_OR_NULL : ZPP_ERROR_WRONG_CLASS_OR_LONG; \
1690
+ break; \
1691
+ }
1692
+
1693
+ #define Z_PARAM_OBJ_OF_CLASS_OR_LONG (dest_obj , _ce , dest_long ) \
1694
+ Z_PARAM_OBJ_OF_CLASS_OR_LONG_EX(dest_obj, _ce, dest_long, _dummy, 0)
1695
+
1696
+ #define Z_PARAM_OBJ_OF_CLASS_OR_LONG_OR_NULL (dest_obj , _ce , dest_long , is_null ) \
1697
+ Z_PARAM_OBJ_OF_CLASS_OR_LONG_EX(dest_obj, _ce, dest_long, is_null, 1)
1698
+
1641
1699
/* old "p" */
1642
1700
#define Z_PARAM_PATH_EX2 (dest , dest_len , check_null , deref , separate ) \
1643
1701
Z_PARAM_PROLOGUE(deref, separate); \
@@ -1991,6 +2049,28 @@ static zend_always_inline bool zend_parse_arg_array_ht(zval *arg, HashTable **de
1991
2049
return 1 ;
1992
2050
}
1993
2051
2052
+ static zend_always_inline bool zend_parse_arg_array_ht_or_long (
2053
+ zval * arg , HashTable * * dest_ht , zend_long * dest_long , zend_bool * is_null , bool allow_null
2054
+ ) {
2055
+ if (allow_null ) {
2056
+ * is_null = 0 ;
2057
+ }
2058
+
2059
+ if (EXPECTED (Z_TYPE_P (arg ) == IS_ARRAY )) {
2060
+ * dest_ht = Z_ARRVAL_P (arg );
2061
+ } else if (EXPECTED (Z_TYPE_P (arg ) == IS_LONG )) {
2062
+ * dest_ht = NULL ;
2063
+ * dest_long = Z_LVAL_P (arg );
2064
+ } else if (allow_null && EXPECTED (Z_TYPE_P (arg ) == IS_NULL )) {
2065
+ * dest_ht = NULL ;
2066
+ * is_null = 1 ;
2067
+ } else {
2068
+ return zend_parse_arg_long_slow (arg , dest_long );
2069
+ }
2070
+
2071
+ return 1 ;
2072
+ }
2073
+
1994
2074
static zend_always_inline bool zend_parse_arg_object (zval * arg , zval * * dest , zend_class_entry * ce , bool check_null )
1995
2075
{
1996
2076
if (EXPECTED (Z_TYPE_P (arg ) == IS_OBJECT ) &&
@@ -2017,6 +2097,28 @@ static zend_always_inline bool zend_parse_arg_obj(zval *arg, zend_object **dest,
2017
2097
return 1 ;
2018
2098
}
2019
2099
2100
+ static zend_always_inline bool zend_parse_arg_obj_or_long (
2101
+ zval * arg , zend_object * * dest_obj , zend_class_entry * ce , zend_long * dest_long , zend_bool * is_null , bool allow_null
2102
+ ) {
2103
+ if (allow_null ) {
2104
+ * is_null = 0 ;
2105
+ }
2106
+
2107
+ if (EXPECTED (Z_TYPE_P (arg ) == IS_OBJECT ) && EXPECTED (instanceof_function (Z_OBJCE_P (arg ), ce ) != 0 )) {
2108
+ * dest_obj = Z_OBJ_P (arg );
2109
+ } else if (EXPECTED (Z_TYPE_P (arg ) == IS_LONG )) {
2110
+ * dest_obj = NULL ;
2111
+ * dest_long = Z_LVAL_P (arg );
2112
+ } else if (allow_null && EXPECTED (Z_TYPE_P (arg ) == IS_NULL )) {
2113
+ * dest_obj = NULL ;
2114
+ * is_null = 1 ;
2115
+ } else {
2116
+ return zend_parse_arg_long_slow (arg , dest_long );
2117
+ }
2118
+
2119
+ return 1 ;
2120
+ }
2121
+
2020
2122
static zend_always_inline bool zend_parse_arg_resource (zval * arg , zval * * dest , bool check_null )
2021
2123
{
2022
2124
if (EXPECTED (Z_TYPE_P (arg ) == IS_RESOURCE )) {
0 commit comments