xref: /PHP-8.2/Zend/zend_API.h (revision a45bef0a)
1 /*
2    +----------------------------------------------------------------------+
3    | Zend Engine                                                          |
4    +----------------------------------------------------------------------+
5    | Copyright (c) Zend Technologies Ltd. (http://www.zend.com)           |
6    +----------------------------------------------------------------------+
7    | This source file is subject to version 2.00 of the Zend license,     |
8    | that is bundled with this package in the file LICENSE, and is        |
9    | available through the world-wide-web at the following url:           |
10    | http://www.zend.com/license/2_00.txt.                                |
11    | If you did not receive a copy of the Zend license and are unable to  |
12    | obtain it through the world-wide-web, please send a note to          |
13    | license@zend.com so we can mail you a copy immediately.              |
14    +----------------------------------------------------------------------+
15    | Authors: Andi Gutmans <andi@php.net>                                 |
16    |          Zeev Suraski <zeev@php.net>                                 |
17    |          Andrei Zmievski <andrei@php.net>                            |
18    |          Dmitry Stogov <dmitry@php.net>                              |
19    +----------------------------------------------------------------------+
20 */
21 
22 #ifndef ZEND_API_H
23 #define ZEND_API_H
24 
25 #include "zend_modules.h"
26 #include "zend_list.h"
27 #include "zend_operators.h"
28 #include "zend_variables.h"
29 #include "zend_execute.h"
30 #include "zend_type_info.h"
31 
32 
33 BEGIN_EXTERN_C()
34 
35 typedef struct _zend_function_entry {
36 	const char *fname;
37 	zif_handler handler;
38 	const struct _zend_internal_arg_info *arg_info;
39 	uint32_t num_args;
40 	uint32_t flags;
41 } zend_function_entry;
42 
43 typedef struct _zend_fcall_info {
44 	size_t size;
45 	zval function_name;
46 	zval *retval;
47 	zval *params;
48 	zend_object *object;
49 	uint32_t param_count;
50 	/* This hashtable can also contain positional arguments (with integer keys),
51 	 * which will be appended to the normal params[]. This makes it easier to
52 	 * integrate APIs like call_user_func_array(). The usual restriction that
53 	 * there may not be position arguments after named arguments applies. */
54 	HashTable *named_params;
55 } zend_fcall_info;
56 
57 typedef struct _zend_fcall_info_cache {
58 	zend_function *function_handler;
59 	zend_class_entry *calling_scope;
60 	zend_class_entry *called_scope;
61 	zend_object *object;
62 } zend_fcall_info_cache;
63 
64 #define ZEND_NS_NAME(ns, name)			ns "\\" name
65 
66 /* ZEND_FN/ZEND_MN are inlined below to prevent pre-scan macro expansion,
67  * which causes issues if the function name is also a macro name. */
68 #define ZEND_FN(name) zif_##name
69 #define ZEND_MN(name) zim_##name
70 
71 #define ZEND_NAMED_FUNCTION(name)		void ZEND_FASTCALL name(INTERNAL_FUNCTION_PARAMETERS)
72 #define ZEND_FUNCTION(name)				ZEND_NAMED_FUNCTION(zif_##name)
73 #define ZEND_METHOD(classname, name)	ZEND_NAMED_FUNCTION(zim_##classname##_##name)
74 
75 #define ZEND_FENTRY(zend_name, name, arg_info, flags)	{ #zend_name, name, arg_info, (uint32_t) (sizeof(arg_info)/sizeof(struct _zend_internal_arg_info)-1), flags },
76 
77 #define ZEND_RAW_FENTRY(zend_name, name, arg_info, flags)   { zend_name, name, arg_info, (uint32_t) (sizeof(arg_info)/sizeof(struct _zend_internal_arg_info)-1), flags },
78 
79 /* Same as ZEND_NAMED_FE */
80 #define ZEND_RAW_NAMED_FE(zend_name, name, arg_info) ZEND_RAW_FENTRY(#zend_name, name, arg_info, 0)
81 
82 #define ZEND_NAMED_FE(zend_name, name, arg_info)	ZEND_RAW_FENTRY(#zend_name, name, arg_info, 0)
83 #define ZEND_FE(name, arg_info)						ZEND_RAW_FENTRY(#name, zif_##name, arg_info, 0)
84 #define ZEND_DEP_FE(name, arg_info)                 ZEND_RAW_FENTRY(#name, zif_##name, arg_info, ZEND_ACC_DEPRECATED)
85 #define ZEND_FALIAS(name, alias, arg_info)			ZEND_RAW_FENTRY(#name, zif_##alias, arg_info, 0)
86 #define ZEND_DEP_FALIAS(name, alias, arg_info)		ZEND_RAW_FENTRY(#name, zif_##alias, arg_info, ZEND_ACC_DEPRECATED)
87 #define ZEND_NAMED_ME(zend_name, name, arg_info, flags)	ZEND_FENTRY(zend_name, name, arg_info, flags)
88 #define ZEND_ME(classname, name, arg_info, flags)	ZEND_RAW_FENTRY(#name, zim_##classname##_##name, arg_info, flags)
89 #define ZEND_DEP_ME(classname, name, arg_info, flags) ZEND_RAW_FENTRY(#name, zim_##classname##_##name, arg_info, flags | ZEND_ACC_DEPRECATED)
90 #define ZEND_ABSTRACT_ME(classname, name, arg_info)	ZEND_RAW_FENTRY(#name, NULL, arg_info, ZEND_ACC_PUBLIC|ZEND_ACC_ABSTRACT)
91 #define ZEND_ABSTRACT_ME_WITH_FLAGS(classname, name, arg_info, flags)	ZEND_RAW_FENTRY(#name, NULL, arg_info, flags)
92 #define ZEND_MALIAS(classname, name, alias, arg_info, flags) ZEND_RAW_FENTRY(#name, zim_##classname##_##alias, arg_info, flags)
93 #define ZEND_ME_MAPPING(name, func_name, arg_info, flags) ZEND_RAW_FENTRY(#name, zif_##func_name, arg_info, flags)
94 
95 #define ZEND_NS_FENTRY(ns, zend_name, name, arg_info, flags)		ZEND_RAW_FENTRY(ZEND_NS_NAME(ns, #zend_name), name, arg_info, flags)
96 
97 #define ZEND_NS_RAW_FENTRY(ns, zend_name, name, arg_info, flags)	ZEND_RAW_FENTRY(ZEND_NS_NAME(ns, zend_name), name, arg_info, flags)
98 /**
99  * Note that if you are asserting that a function is compile-time evaluable, you are asserting that
100  *
101  * 1. The function will always have the same result for the same arguments
102  * 2. The function does not depend on global state such as ini settings or locale (e.g. mb_strtolower), number_format(), etc.
103  * 3. The function does not have side effects. It is okay if they throw
104  *    or warn on invalid arguments, as we detect this and will discard the evaluation result.
105  * 4. The function will not take an unreasonable amount of time or memory to compute on code that may be seen in practice.
106  *    (e.g. str_repeat is special cased to check the length instead of using this)
107  */
108 #define ZEND_SUPPORTS_COMPILE_TIME_EVAL_FE(name, arg_info) ZEND_RAW_FENTRY(#name, zif_##name, arg_info, ZEND_ACC_COMPILE_TIME_EVAL)
109 
110 /* Same as ZEND_NS_NAMED_FE */
111 #define ZEND_NS_RAW_NAMED_FE(ns, zend_name, name, arg_info)			ZEND_NS_RAW_FENTRY(ns, #zend_name, name, arg_info, 0)
112 
113 #define ZEND_NS_NAMED_FE(ns, zend_name, name, arg_info)	ZEND_NS_RAW_FENTRY(ns, #zend_name, name, arg_info, 0)
114 #define ZEND_NS_FE(ns, name, arg_info)					ZEND_NS_RAW_FENTRY(ns, #name, zif_##name, arg_info, 0)
115 #define ZEND_NS_DEP_FE(ns, name, arg_info)				ZEND_NS_RAW_FENTRY(ns, #name, zif_##name, arg_info, ZEND_ACC_DEPRECATED)
116 #define ZEND_NS_FALIAS(ns, name, alias, arg_info)		ZEND_NS_RAW_FENTRY(ns, #name, zif_##alias, arg_info, 0)
117 #define ZEND_NS_DEP_FALIAS(ns, name, alias, arg_info)	ZEND_NS_RAW_FENTRY(ns, #name, zif_##alias, arg_info, ZEND_ACC_DEPRECATED)
118 
119 #define ZEND_FE_END            { NULL, NULL, NULL, 0, 0 }
120 
121 #define _ZEND_ARG_INFO_FLAGS(pass_by_ref, is_variadic, is_tentative) \
122 	(((pass_by_ref) << _ZEND_SEND_MODE_SHIFT) | ((is_variadic) ? _ZEND_IS_VARIADIC_BIT : 0) | ((is_tentative) ? _ZEND_IS_TENTATIVE_BIT : 0))
123 
124 /* Arginfo structures without type information */
125 #define ZEND_ARG_INFO(pass_by_ref, name) \
126 	{ #name, ZEND_TYPE_INIT_NONE(_ZEND_ARG_INFO_FLAGS(pass_by_ref, 0, 0)), NULL },
127 #define ZEND_ARG_INFO_WITH_DEFAULT_VALUE(pass_by_ref, name, default_value) \
128 	{ #name, ZEND_TYPE_INIT_NONE(_ZEND_ARG_INFO_FLAGS(pass_by_ref, 0, 0)), default_value },
129 #define ZEND_ARG_VARIADIC_INFO(pass_by_ref, name) \
130 	{ #name, ZEND_TYPE_INIT_NONE(_ZEND_ARG_INFO_FLAGS(pass_by_ref, 1, 0)), NULL },
131 
132 /* Arginfo structures with simple type information */
133 #define ZEND_ARG_TYPE_INFO(pass_by_ref, name, type_hint, allow_null) \
134 	{ #name, ZEND_TYPE_INIT_CODE(type_hint, allow_null, _ZEND_ARG_INFO_FLAGS(pass_by_ref, 0, 0)), NULL },
135 #define ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(pass_by_ref, name, type_hint, allow_null, default_value) \
136 	{ #name, ZEND_TYPE_INIT_CODE(type_hint, allow_null, _ZEND_ARG_INFO_FLAGS(pass_by_ref, 0, 0)), default_value },
137 #define ZEND_ARG_VARIADIC_TYPE_INFO(pass_by_ref, name, type_hint, allow_null) \
138 	{ #name, ZEND_TYPE_INIT_CODE(type_hint, allow_null, _ZEND_ARG_INFO_FLAGS(pass_by_ref, 1, 0)), NULL },
139 
140 /* Arginfo structures with complex type information */
141 #define ZEND_ARG_TYPE_MASK(pass_by_ref, name, type_mask, default_value) \
142 	{ #name, ZEND_TYPE_INIT_MASK(type_mask | _ZEND_ARG_INFO_FLAGS(pass_by_ref, 0, 0)), default_value },
143 #define ZEND_ARG_OBJ_TYPE_MASK(pass_by_ref, name, class_name, type_mask, default_value) \
144 	{ #name, ZEND_TYPE_INIT_CLASS_CONST_MASK(#class_name, type_mask | _ZEND_ARG_INFO_FLAGS(pass_by_ref, 0, 0)), default_value },
145 #define ZEND_ARG_VARIADIC_OBJ_TYPE_MASK(pass_by_ref, name, class_name, type_mask) \
146 	{ #name, ZEND_TYPE_INIT_CLASS_CONST_MASK(#class_name, type_mask | _ZEND_ARG_INFO_FLAGS(pass_by_ref, 1, 0)), NULL },
147 
148 /* Arginfo structures with object type information */
149 #define ZEND_ARG_OBJ_INFO(pass_by_ref, name, class_name, allow_null) \
150 	{ #name, ZEND_TYPE_INIT_CLASS_CONST(#class_name, allow_null, _ZEND_ARG_INFO_FLAGS(pass_by_ref, 0, 0)), NULL },
151 #define ZEND_ARG_OBJ_INFO_WITH_DEFAULT_VALUE(pass_by_ref, name, class_name, allow_null, default_value) \
152 	{ #name, ZEND_TYPE_INIT_CLASS_CONST(#class_name, allow_null, _ZEND_ARG_INFO_FLAGS(pass_by_ref, 0, 0)), default_value },
153 #define ZEND_ARG_VARIADIC_OBJ_INFO(pass_by_ref, name, class_name, allow_null) \
154 	{ #name, ZEND_TYPE_INIT_CLASS_CONST(#class_name, allow_null, _ZEND_ARG_INFO_FLAGS(pass_by_ref, 1, 0)), NULL },
155 
156 /* Legacy arginfo structures */
157 #define ZEND_ARG_ARRAY_INFO(pass_by_ref, name, allow_null) \
158 	{ #name, ZEND_TYPE_INIT_CODE(IS_ARRAY, allow_null, _ZEND_ARG_INFO_FLAGS(pass_by_ref, 0, 0)), NULL },
159 #define ZEND_ARG_CALLABLE_INFO(pass_by_ref, name, allow_null) \
160 	{ #name, ZEND_TYPE_INIT_CODE(IS_CALLABLE, allow_null, _ZEND_ARG_INFO_FLAGS(pass_by_ref, 0, 0)), NULL },
161 
162 #define ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX2(name, return_reference, required_num_args, class_name, allow_null, is_tentative_return_type) \
163 	static const zend_internal_arg_info name[] = { \
164 		{ (const char*)(zend_uintptr_t)(required_num_args), \
165 			ZEND_TYPE_INIT_CLASS_CONST(#class_name, allow_null, _ZEND_ARG_INFO_FLAGS(return_reference, 0, is_tentative_return_type)), NULL },
166 
167 #define ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(name, return_reference, required_num_args, class_name, allow_null) \
168 	ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX2(name, return_reference, required_num_args, class_name, allow_null, 0)
169 
170 #define ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_OBJ_INFO_EX(name, return_reference, required_num_args, class_name, allow_null) \
171 	ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX2(name, return_reference, required_num_args, class_name, allow_null, 1)
172 
173 #define ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO(name, class_name, allow_null) \
174 	ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX2(name, 0, -1, class_name, allow_null, 0)
175 
176 #define ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX2(name, return_reference, required_num_args, type, is_tentative_return_type) \
177 	static const zend_internal_arg_info name[] = { \
178 		{ (const char*)(zend_uintptr_t)(required_num_args), ZEND_TYPE_INIT_MASK(type | _ZEND_ARG_INFO_FLAGS(return_reference, 0, is_tentative_return_type)), NULL },
179 
180 #define ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(name, return_reference, required_num_args, type) \
181 	ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX2(name, return_reference, required_num_args, type, 0)
182 
183 #define ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_MASK_EX(name, return_reference, required_num_args, type) \
184 	ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX2(name, return_reference, required_num_args, type, 1)
185 
186 #define ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX2(name, return_reference, required_num_args, class_name, type, is_tentative_return_type) \
187 	static const zend_internal_arg_info name[] = { \
188 		{ (const char*)(zend_uintptr_t)(required_num_args), ZEND_TYPE_INIT_CLASS_CONST_MASK(#class_name, type | _ZEND_ARG_INFO_FLAGS(return_reference, 0, is_tentative_return_type)), NULL },
189 
190 #define ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(name, return_reference, required_num_args, class_name, type) \
191 	ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX2(name, return_reference, required_num_args, class_name, type, 0)
192 
193 #define ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_OBJ_TYPE_MASK_EX(name, return_reference, required_num_args, class_name, type) \
194 	ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX2(name, return_reference, required_num_args, class_name, type, 1)
195 
196 #define ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX2(name, return_reference, required_num_args, type, allow_null, is_tentative_return_type) \
197 	static const zend_internal_arg_info name[] = { \
198 		{ (const char*)(zend_uintptr_t)(required_num_args), ZEND_TYPE_INIT_CODE(type, allow_null, _ZEND_ARG_INFO_FLAGS(return_reference, 0, is_tentative_return_type)), NULL },
199 
200 #define ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(name, return_reference, required_num_args, type, allow_null) \
201 	ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX2(name, return_reference, required_num_args, type, allow_null, 0)
202 
203 #define ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_INFO_EX(name, return_reference, required_num_args, type, allow_null) \
204 	ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX2(name, return_reference, required_num_args, type, allow_null, 1)
205 
206 #define ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(name, type, allow_null) \
207 	ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX2(name, 0, -1, type, allow_null, 0)
208 
209 #define ZEND_BEGIN_ARG_INFO_EX(name, _unused, return_reference, required_num_args)	\
210 	static const zend_internal_arg_info name[] = { \
211 		{ (const char*)(zend_uintptr_t)(required_num_args), ZEND_TYPE_INIT_NONE(_ZEND_ARG_INFO_FLAGS(return_reference, 0, 0)), NULL },
212 #define ZEND_BEGIN_ARG_INFO(name, _unused)	\
213 	ZEND_BEGIN_ARG_INFO_EX(name, {}, ZEND_RETURN_VALUE, -1)
214 #define ZEND_END_ARG_INFO()		};
215 
216 /* Name macros */
217 #define ZEND_MODULE_STARTUP_N(module)       zm_startup_##module
218 #define ZEND_MODULE_SHUTDOWN_N(module)		zm_shutdown_##module
219 #define ZEND_MODULE_ACTIVATE_N(module)		zm_activate_##module
220 #define ZEND_MODULE_DEACTIVATE_N(module)	zm_deactivate_##module
221 #define ZEND_MODULE_POST_ZEND_DEACTIVATE_N(module)	zm_post_zend_deactivate_##module
222 #define ZEND_MODULE_INFO_N(module)			zm_info_##module
223 #define ZEND_MODULE_GLOBALS_CTOR_N(module)  zm_globals_ctor_##module
224 #define ZEND_MODULE_GLOBALS_DTOR_N(module)  zm_globals_dtor_##module
225 
226 /* Declaration macros */
227 #define ZEND_MODULE_STARTUP_D(module)		zend_result ZEND_MODULE_STARTUP_N(module)(INIT_FUNC_ARGS)
228 #define ZEND_MODULE_SHUTDOWN_D(module)		zend_result ZEND_MODULE_SHUTDOWN_N(module)(SHUTDOWN_FUNC_ARGS)
229 #define ZEND_MODULE_ACTIVATE_D(module)		zend_result ZEND_MODULE_ACTIVATE_N(module)(INIT_FUNC_ARGS)
230 #define ZEND_MODULE_DEACTIVATE_D(module)	zend_result ZEND_MODULE_DEACTIVATE_N(module)(SHUTDOWN_FUNC_ARGS)
231 #define ZEND_MODULE_POST_ZEND_DEACTIVATE_D(module)	zend_result ZEND_MODULE_POST_ZEND_DEACTIVATE_N(module)(void)
232 #define ZEND_MODULE_INFO_D(module)			ZEND_COLD void ZEND_MODULE_INFO_N(module)(ZEND_MODULE_INFO_FUNC_ARGS)
233 #define ZEND_MODULE_GLOBALS_CTOR_D(module)  void ZEND_MODULE_GLOBALS_CTOR_N(module)(zend_##module##_globals *module##_globals)
234 #define ZEND_MODULE_GLOBALS_DTOR_D(module)  void ZEND_MODULE_GLOBALS_DTOR_N(module)(zend_##module##_globals *module##_globals)
235 
236 #define ZEND_GET_MODULE(name) \
237     BEGIN_EXTERN_C()\
238 	ZEND_DLEXPORT zend_module_entry *get_module(void) { return &name##_module_entry; }\
239     END_EXTERN_C()
240 
241 #define ZEND_BEGIN_MODULE_GLOBALS(module_name)		\
242 	typedef struct _zend_##module_name##_globals {
243 #define ZEND_END_MODULE_GLOBALS(module_name)		\
244 	} zend_##module_name##_globals;
245 
246 #ifdef ZTS
247 
248 #define ZEND_DECLARE_MODULE_GLOBALS(module_name)							\
249 	ts_rsrc_id module_name##_globals_id;
250 #define ZEND_EXTERN_MODULE_GLOBALS(module_name)								\
251 	extern ts_rsrc_id module_name##_globals_id;
252 #define ZEND_INIT_MODULE_GLOBALS(module_name, globals_ctor, globals_dtor)	\
253 	ts_allocate_id(&module_name##_globals_id, sizeof(zend_##module_name##_globals), (ts_allocate_ctor) globals_ctor, (ts_allocate_dtor) globals_dtor);
254 #define ZEND_MODULE_GLOBALS_ACCESSOR(module_name, v) ZEND_TSRMG(module_name##_globals_id, zend_##module_name##_globals *, v)
255 #ifdef ZEND_ENABLE_STATIC_TSRMLS_CACHE
256 #define ZEND_MODULE_GLOBALS_BULK(module_name) TSRMG_BULK_STATIC(module_name##_globals_id, zend_##module_name##_globals *)
257 #else
258 #define ZEND_MODULE_GLOBALS_BULK(module_name) TSRMG_BULK(module_name##_globals_id, zend_##module_name##_globals *)
259 #endif
260 
261 #else
262 
263 #define ZEND_DECLARE_MODULE_GLOBALS(module_name)							\
264 	zend_##module_name##_globals module_name##_globals;
265 #define ZEND_EXTERN_MODULE_GLOBALS(module_name)								\
266 	extern zend_##module_name##_globals module_name##_globals;
267 #define ZEND_INIT_MODULE_GLOBALS(module_name, globals_ctor, globals_dtor)	\
268 	globals_ctor(&module_name##_globals);
269 #define ZEND_MODULE_GLOBALS_ACCESSOR(module_name, v) (module_name##_globals.v)
270 #define ZEND_MODULE_GLOBALS_BULK(module_name) (&module_name##_globals)
271 
272 #endif
273 
274 #define INIT_CLASS_ENTRY(class_container, class_name, functions) \
275 	INIT_CLASS_ENTRY_EX(class_container, class_name, sizeof(class_name)-1, functions)
276 
277 #define INIT_CLASS_ENTRY_EX(class_container, class_name, class_name_len, functions) \
278 	{															\
279 		memset(&class_container, 0, sizeof(zend_class_entry)); \
280 		class_container.name = zend_string_init_interned(class_name, class_name_len, 1); \
281 		class_container.info.internal.builtin_functions = functions;	\
282 	}
283 
284 #define INIT_CLASS_ENTRY_INIT_METHODS(class_container, functions) \
285 	{															\
286 		class_container.constructor = NULL;						\
287 		class_container.destructor = NULL;						\
288 		class_container.clone = NULL;							\
289 		class_container.serialize = NULL;						\
290 		class_container.unserialize = NULL;						\
291 		class_container.create_object = NULL;					\
292 		class_container.get_static_method = NULL;				\
293 		class_container.__call = NULL;							\
294 		class_container.__callstatic = NULL;					\
295 		class_container.__tostring = NULL;						\
296 		class_container.__get = NULL;							\
297 		class_container.__set = NULL;							\
298 		class_container.__unset = NULL;							\
299 		class_container.__isset = NULL;							\
300 		class_container.__debugInfo = NULL;						\
301 		class_container.__serialize = NULL;						\
302 		class_container.__unserialize = NULL;					\
303 		class_container.parent = NULL;							\
304 		class_container.num_interfaces = 0;						\
305 		class_container.trait_names = NULL;						\
306 		class_container.num_traits = 0;							\
307 		class_container.trait_aliases = NULL;					\
308 		class_container.trait_precedences = NULL;				\
309 		class_container.interfaces = NULL;						\
310 		class_container.get_iterator = NULL;					\
311 		class_container.iterator_funcs_ptr = NULL;				\
312 		class_container.arrayaccess_funcs_ptr = NULL;			\
313 		class_container.info.internal.module = NULL;			\
314 		class_container.info.internal.builtin_functions = functions;	\
315 	}
316 
317 
318 #define INIT_NS_CLASS_ENTRY(class_container, ns, class_name, functions) \
319 	INIT_CLASS_ENTRY(class_container, ZEND_NS_NAME(ns, class_name), functions)
320 
321 #define CE_STATIC_MEMBERS(ce) \
322 	((zval*)ZEND_MAP_PTR_GET((ce)->static_members_table))
323 
324 #define CE_CONSTANTS_TABLE(ce) \
325 	zend_class_constants_table(ce)
326 
327 #define CE_DEFAULT_PROPERTIES_TABLE(ce) \
328 	zend_class_default_properties_table(ce)
329 
330 #define CE_BACKED_ENUM_TABLE(ce) \
331 	zend_class_backed_enum_table(ce)
332 
333 #define ZEND_FCI_INITIALIZED(fci) ((fci).size != 0)
334 
335 ZEND_API int zend_next_free_module(void);
336 
337 BEGIN_EXTERN_C()
338 ZEND_API zend_result zend_get_parameters_array_ex(uint32_t param_count, zval *argument_array);
339 
340 /* internal function to efficiently copy parameters when executing __call() */
341 ZEND_API zend_result zend_copy_parameters_array(uint32_t param_count, zval *argument_array);
342 
343 #define zend_get_parameters_array(ht, param_count, argument_array) \
344 	zend_get_parameters_array_ex(param_count, argument_array)
345 #define zend_parse_parameters_none() \
346 	(EXPECTED(ZEND_NUM_ARGS() == 0) ? SUCCESS : (zend_wrong_parameters_none_error(), FAILURE))
347 #define zend_parse_parameters_none_throw() \
348 	zend_parse_parameters_none()
349 
350 /* Parameter parsing API -- andrei */
351 
352 #define ZEND_PARSE_PARAMS_THROW 0 /* No longer used, zpp always uses exceptions */
353 #define ZEND_PARSE_PARAMS_QUIET (1<<1)
354 ZEND_API zend_result zend_parse_parameters(uint32_t num_args, const char *type_spec, ...);
355 ZEND_API zend_result zend_parse_parameters_ex(int flags, uint32_t num_args, const char *type_spec, ...);
356 /* NOTE: This must have at least one value in __VA_ARGS__ for the expression to be valid */
357 #define zend_parse_parameters_throw(num_args, ...) \
358 	zend_parse_parameters(num_args, __VA_ARGS__)
359 ZEND_API const char *zend_zval_type_name(const zval *arg);
360 ZEND_API zend_string *zend_zval_get_legacy_type(const zval *arg);
361 
362 ZEND_API zend_result zend_parse_method_parameters(uint32_t num_args, zval *this_ptr, const char *type_spec, ...);
363 ZEND_API zend_result zend_parse_method_parameters_ex(int flags, uint32_t num_args, zval *this_ptr, const char *type_spec, ...);
364 
365 ZEND_API zend_result zend_parse_parameter(int flags, uint32_t arg_num, zval *arg, const char *spec, ...);
366 
367 /* End of parameter parsing API -- andrei */
368 
369 ZEND_API zend_result zend_register_functions(zend_class_entry *scope, const zend_function_entry *functions, HashTable *function_table, int type);
370 ZEND_API void zend_unregister_functions(const zend_function_entry *functions, int count, HashTable *function_table);
371 ZEND_API zend_result zend_startup_module(zend_module_entry *module_entry);
372 ZEND_API zend_module_entry* zend_register_internal_module(zend_module_entry *module_entry);
373 ZEND_API zend_module_entry* zend_register_module_ex(zend_module_entry *module);
374 ZEND_API zend_result zend_startup_module_ex(zend_module_entry *module);
375 ZEND_API void zend_startup_modules(void);
376 ZEND_API void zend_collect_module_handlers(void);
377 ZEND_API void zend_destroy_modules(void);
378 ZEND_API void zend_check_magic_method_implementation(
379 		const zend_class_entry *ce, const zend_function *fptr, zend_string *lcname, int error_type);
380 ZEND_API void zend_add_magic_method(zend_class_entry *ce, zend_function *fptr, zend_string *lcname);
381 
382 ZEND_API zend_class_entry *zend_register_internal_class(zend_class_entry *class_entry);
383 ZEND_API zend_class_entry *zend_register_internal_class_ex(zend_class_entry *class_entry, zend_class_entry *parent_ce);
384 ZEND_API zend_class_entry *zend_register_internal_interface(zend_class_entry *orig_class_entry);
385 ZEND_API void zend_class_implements(zend_class_entry *class_entry, int num_interfaces, ...);
386 
387 ZEND_API zend_result zend_register_class_alias_ex(const char *name, size_t name_len, zend_class_entry *ce, bool persistent);
388 
zend_register_class_alias(const char * name,zend_class_entry * ce)389 static zend_always_inline zend_result zend_register_class_alias(const char *name, zend_class_entry *ce) {
390 	return zend_register_class_alias_ex(name, strlen(name), ce, 1);
391 }
392 #define zend_register_ns_class_alias(ns, name, ce) \
393 	zend_register_class_alias_ex(ZEND_NS_NAME(ns, name), sizeof(ZEND_NS_NAME(ns, name))-1, ce, 1)
394 
395 ZEND_API void zend_disable_functions(const char *function_list);
396 ZEND_API zend_result zend_disable_class(const char *class_name, size_t class_name_length);
397 
398 ZEND_API ZEND_COLD void zend_wrong_param_count(void);
399 ZEND_API ZEND_COLD void zend_wrong_property_read(zval *object, zval *property);
400 
401 #define IS_CALLABLE_CHECK_SYNTAX_ONLY (1<<0)
402 #define IS_CALLABLE_SUPPRESS_DEPRECATIONS (1<<1)
403 
404 ZEND_API void zend_release_fcall_info_cache(zend_fcall_info_cache *fcc);
405 ZEND_API zend_string *zend_get_callable_name_ex(zval *callable, zend_object *object);
406 ZEND_API zend_string *zend_get_callable_name(zval *callable);
407 ZEND_API bool zend_is_callable_at_frame(
408 		zval *callable, zend_object *object, zend_execute_data *frame,
409 		uint32_t check_flags, zend_fcall_info_cache *fcc, char **error);
410 ZEND_API bool zend_is_callable_ex(zval *callable, zend_object *object, uint32_t check_flags, zend_string **callable_name, zend_fcall_info_cache *fcc, char **error);
411 ZEND_API bool zend_is_callable(zval *callable, uint32_t check_flags, zend_string **callable_name);
412 ZEND_API bool zend_make_callable(zval *callable, zend_string **callable_name);
413 ZEND_API const char *zend_get_module_version(const char *module_name);
414 ZEND_API int zend_get_module_started(const char *module_name);
415 
416 ZEND_API zend_property_info *zend_declare_typed_property(zend_class_entry *ce, zend_string *name, zval *property, int access_type, zend_string *doc_comment, zend_type type);
417 
418 ZEND_API void zend_declare_property_ex(zend_class_entry *ce, zend_string *name, zval *property, int access_type, zend_string *doc_comment);
419 ZEND_API void zend_declare_property(zend_class_entry *ce, const char *name, size_t name_length, zval *property, int access_type);
420 ZEND_API void zend_declare_property_null(zend_class_entry *ce, const char *name, size_t name_length, int access_type);
421 ZEND_API void zend_declare_property_bool(zend_class_entry *ce, const char *name, size_t name_length, zend_long value, int access_type);
422 ZEND_API void zend_declare_property_long(zend_class_entry *ce, const char *name, size_t name_length, zend_long value, int access_type);
423 ZEND_API void zend_declare_property_double(zend_class_entry *ce, const char *name, size_t name_length, double value, int access_type);
424 ZEND_API void zend_declare_property_string(zend_class_entry *ce, const char *name, size_t name_length, const char *value, int access_type);
425 ZEND_API void zend_declare_property_stringl(zend_class_entry *ce, const char *name, size_t name_length, const char *value, size_t value_len, int access_type);
426 
427 ZEND_API zend_class_constant *zend_declare_class_constant_ex(zend_class_entry *ce, zend_string *name, zval *value, int access_type, zend_string *doc_comment);
428 ZEND_API void zend_declare_class_constant(zend_class_entry *ce, const char *name, size_t name_length, zval *value);
429 ZEND_API void zend_declare_class_constant_null(zend_class_entry *ce, const char *name, size_t name_length);
430 ZEND_API void zend_declare_class_constant_long(zend_class_entry *ce, const char *name, size_t name_length, zend_long value);
431 ZEND_API void zend_declare_class_constant_bool(zend_class_entry *ce, const char *name, size_t name_length, bool value);
432 ZEND_API void zend_declare_class_constant_double(zend_class_entry *ce, const char *name, size_t name_length, double value);
433 ZEND_API void zend_declare_class_constant_stringl(zend_class_entry *ce, const char *name, size_t name_length, const char *value, size_t value_length);
434 ZEND_API void zend_declare_class_constant_string(zend_class_entry *ce, const char *name, size_t name_length, const char *value);
435 
436 ZEND_API zend_result zend_update_class_constants(zend_class_entry *class_type);
437 ZEND_API HashTable *zend_separate_class_constants_table(zend_class_entry *class_type);
438 
zend_class_constants_table(zend_class_entry * ce)439 static zend_always_inline HashTable *zend_class_constants_table(zend_class_entry *ce) {
440 	if ((ce->ce_flags & ZEND_ACC_HAS_AST_CONSTANTS) && ZEND_MAP_PTR(ce->mutable_data)) {
441 		zend_class_mutable_data *mutable_data =
442 			(zend_class_mutable_data*)ZEND_MAP_PTR_GET_IMM(ce->mutable_data);
443 		if (mutable_data && mutable_data->constants_table) {
444 			return mutable_data->constants_table;
445 		} else {
446 			return zend_separate_class_constants_table(ce);
447 		}
448 	} else {
449 		return &ce->constants_table;
450 	}
451 }
452 
zend_class_default_properties_table(zend_class_entry * ce)453 static zend_always_inline zval *zend_class_default_properties_table(zend_class_entry *ce) {
454 	if ((ce->ce_flags & ZEND_ACC_HAS_AST_PROPERTIES) && ZEND_MAP_PTR(ce->mutable_data)) {
455 		zend_class_mutable_data *mutable_data =
456 			(zend_class_mutable_data*)ZEND_MAP_PTR_GET_IMM(ce->mutable_data);
457 		return mutable_data->default_properties_table;
458 	} else {
459 		return ce->default_properties_table;
460 	}
461 }
462 
zend_class_set_backed_enum_table(zend_class_entry * ce,HashTable * backed_enum_table)463 static zend_always_inline void zend_class_set_backed_enum_table(zend_class_entry *ce, HashTable *backed_enum_table)
464 {
465 	if (ZEND_MAP_PTR(ce->mutable_data) && ce->type == ZEND_USER_CLASS) {
466 		zend_class_mutable_data *mutable_data = (zend_class_mutable_data*)ZEND_MAP_PTR_GET_IMM(ce->mutable_data);
467 		mutable_data->backed_enum_table = backed_enum_table;
468 	} else {
469 		ce->backed_enum_table = backed_enum_table;
470 	}
471 }
472 
zend_class_backed_enum_table(zend_class_entry * ce)473 static zend_always_inline HashTable *zend_class_backed_enum_table(zend_class_entry *ce)
474 {
475 	if (ZEND_MAP_PTR(ce->mutable_data) && ce->type == ZEND_USER_CLASS) {
476 		zend_class_mutable_data *mutable_data = (zend_class_mutable_data*)ZEND_MAP_PTR_GET_IMM(ce->mutable_data);
477 		return mutable_data->backed_enum_table;
478 	} else {
479 		return ce->backed_enum_table;
480 	}
481 }
482 
483 ZEND_API void zend_update_property_ex(zend_class_entry *scope, zend_object *object, zend_string *name, zval *value);
484 ZEND_API void zend_update_property(zend_class_entry *scope, zend_object *object, const char *name, size_t name_length, zval *value);
485 ZEND_API void zend_update_property_null(zend_class_entry *scope, zend_object *object, const char *name, size_t name_length);
486 ZEND_API void zend_update_property_bool(zend_class_entry *scope, zend_object *object, const char *name, size_t name_length, zend_long value);
487 ZEND_API void zend_update_property_long(zend_class_entry *scope, zend_object *object, const char *name, size_t name_length, zend_long value);
488 ZEND_API void zend_update_property_double(zend_class_entry *scope, zend_object *object, const char *name, size_t name_length, double value);
489 ZEND_API void zend_update_property_str(zend_class_entry *scope, zend_object *object, const char *name, size_t name_length, zend_string *value);
490 ZEND_API void zend_update_property_string(zend_class_entry *scope, zend_object *object, const char *name, size_t name_length, const char *value);
491 ZEND_API void zend_update_property_stringl(zend_class_entry *scope, zend_object *object, const char *name, size_t name_length, const char *value, size_t value_length);
492 ZEND_API void zend_unset_property(zend_class_entry *scope, zend_object *object, const char *name, size_t name_length);
493 
494 ZEND_API zend_result zend_update_static_property_ex(zend_class_entry *scope, zend_string *name, zval *value);
495 ZEND_API zend_result zend_update_static_property(zend_class_entry *scope, const char *name, size_t name_length, zval *value);
496 ZEND_API zend_result zend_update_static_property_null(zend_class_entry *scope, const char *name, size_t name_length);
497 ZEND_API zend_result zend_update_static_property_bool(zend_class_entry *scope, const char *name, size_t name_length, zend_long value);
498 ZEND_API zend_result zend_update_static_property_long(zend_class_entry *scope, const char *name, size_t name_length, zend_long value);
499 ZEND_API zend_result zend_update_static_property_double(zend_class_entry *scope, const char *name, size_t name_length, double value);
500 ZEND_API zend_result zend_update_static_property_string(zend_class_entry *scope, const char *name, size_t name_length, const char *value);
501 ZEND_API zend_result zend_update_static_property_stringl(zend_class_entry *scope, const char *name, size_t name_length, const char *value, size_t value_length);
502 
503 ZEND_API zval *zend_read_property_ex(zend_class_entry *scope, zend_object *object, zend_string *name, bool silent, zval *rv);
504 ZEND_API zval *zend_read_property(zend_class_entry *scope, zend_object *object, const char *name, size_t name_length, bool silent, zval *rv);
505 
506 ZEND_API zval *zend_read_static_property_ex(zend_class_entry *scope, zend_string *name, bool silent);
507 ZEND_API zval *zend_read_static_property(zend_class_entry *scope, const char *name, size_t name_length, bool silent);
508 
509 ZEND_API const char *zend_get_type_by_const(int type);
510 
511 #define ZEND_THIS                           (&EX(This))
512 
513 #define getThis()							((Z_TYPE_P(ZEND_THIS) == IS_OBJECT) ? ZEND_THIS : NULL)
514 #define ZEND_IS_METHOD_CALL()				(EX(func)->common.scope != NULL)
515 
516 #define WRONG_PARAM_COUNT					ZEND_WRONG_PARAM_COUNT()
517 #define ZEND_NUM_ARGS()						EX_NUM_ARGS()
518 #define ZEND_WRONG_PARAM_COUNT()					{ zend_wrong_param_count(); return; }
519 
520 #ifndef ZEND_WIN32
521 #define DLEXPORT
522 #endif
523 
524 #define array_init(arg)				ZVAL_ARR((arg), zend_new_array(0))
525 #define array_init_size(arg, size)	ZVAL_ARR((arg), zend_new_array(size))
526 ZEND_API void object_init(zval *arg);
527 ZEND_API zend_result object_init_ex(zval *arg, zend_class_entry *ce);
528 ZEND_API zend_result object_and_properties_init(zval *arg, zend_class_entry *ce, HashTable *properties);
529 ZEND_API void object_properties_init(zend_object *object, zend_class_entry *class_type);
530 ZEND_API void object_properties_init_ex(zend_object *object, HashTable *properties);
531 ZEND_API void object_properties_load(zend_object *object, HashTable *properties);
532 
533 ZEND_API void zend_merge_properties(zval *obj, HashTable *properties);
534 
535 ZEND_API void add_assoc_long_ex(zval *arg, const char *key, size_t key_len, zend_long n);
536 ZEND_API void add_assoc_null_ex(zval *arg, const char *key, size_t key_len);
537 ZEND_API void add_assoc_bool_ex(zval *arg, const char *key, size_t key_len, bool b);
538 ZEND_API void add_assoc_resource_ex(zval *arg, const char *key, size_t key_len, zend_resource *r);
539 ZEND_API void add_assoc_double_ex(zval *arg, const char *key, size_t key_len, double d);
540 ZEND_API void add_assoc_str_ex(zval *arg, const char *key, size_t key_len, zend_string *str);
541 ZEND_API void add_assoc_string_ex(zval *arg, const char *key, size_t key_len, const char *str);
542 ZEND_API void add_assoc_stringl_ex(zval *arg, const char *key, size_t key_len, const char *str, size_t length);
543 ZEND_API void add_assoc_array_ex(zval *arg, const char *key, size_t key_len, zend_array *arr);
544 ZEND_API void add_assoc_object_ex(zval *arg, const char *key, size_t key_len, zend_object *obj);
545 ZEND_API void add_assoc_reference_ex(zval *arg, const char *key, size_t key_len, zend_reference *ref);
546 ZEND_API void add_assoc_zval_ex(zval *arg, const char *key, size_t key_len, zval *value);
547 
add_assoc_long(zval * arg,const char * key,zend_long n)548 static zend_always_inline void add_assoc_long(zval *arg, const char *key, zend_long n) {
549 	add_assoc_long_ex(arg, key, strlen(key), n);
550 }
add_assoc_null(zval * arg,const char * key)551 static zend_always_inline void add_assoc_null(zval *arg, const char *key) {
552 	add_assoc_null_ex(arg, key, strlen(key));
553 }
add_assoc_bool(zval * arg,const char * key,bool b)554 static zend_always_inline void add_assoc_bool(zval *arg, const char *key, bool b) {
555 	add_assoc_bool_ex(arg, key, strlen(key), b);
556 }
add_assoc_resource(zval * arg,const char * key,zend_resource * r)557 static zend_always_inline void add_assoc_resource(zval *arg, const char *key, zend_resource *r) {
558 	add_assoc_resource_ex(arg, key, strlen(key), r);
559 }
add_assoc_double(zval * arg,const char * key,double d)560 static zend_always_inline void add_assoc_double(zval *arg, const char *key, double d) {
561 	add_assoc_double_ex(arg, key, strlen(key), d);
562 }
add_assoc_str(zval * arg,const char * key,zend_string * str)563 static zend_always_inline void add_assoc_str(zval *arg, const char *key, zend_string *str) {
564 	add_assoc_str_ex(arg, key, strlen(key), str);
565 }
add_assoc_string(zval * arg,const char * key,const char * str)566 static zend_always_inline void add_assoc_string(zval *arg, const char *key, const char *str) {
567 	add_assoc_string_ex(arg, key, strlen(key), str);
568 }
add_assoc_stringl(zval * arg,const char * key,const char * str,size_t length)569 static zend_always_inline void add_assoc_stringl(zval *arg, const char *key, const char *str, size_t length) {
570 	add_assoc_stringl_ex(arg, key, strlen(key), str, length);
571 }
add_assoc_array(zval * arg,const char * key,zend_array * arr)572 static zend_always_inline void add_assoc_array(zval *arg, const char *key, zend_array *arr) {
573 	add_assoc_array_ex(arg, key, strlen(key), arr);
574 }
add_assoc_object(zval * arg,const char * key,zend_object * obj)575 static zend_always_inline void add_assoc_object(zval *arg, const char *key, zend_object *obj) {
576 	add_assoc_object_ex(arg, key, strlen(key), obj);
577 }
add_assoc_reference(zval * arg,const char * key,zend_reference * ref)578 static zend_always_inline void add_assoc_reference(zval *arg, const char *key, zend_reference *ref) {
579 	add_assoc_reference_ex(arg, key, strlen(key), ref);
580 }
add_assoc_zval(zval * arg,const char * key,zval * value)581 static zend_always_inline void add_assoc_zval(zval *arg, const char *key, zval *value) {
582 	add_assoc_zval_ex(arg, key, strlen(key), value);
583 }
584 
585 ZEND_API void add_index_long(zval *arg, zend_ulong index, zend_long n);
586 ZEND_API void add_index_null(zval *arg, zend_ulong index);
587 ZEND_API void add_index_bool(zval *arg, zend_ulong index, bool b);
588 ZEND_API void add_index_resource(zval *arg, zend_ulong index, zend_resource *r);
589 ZEND_API void add_index_double(zval *arg, zend_ulong index, double d);
590 ZEND_API void add_index_str(zval *arg, zend_ulong index, zend_string *str);
591 ZEND_API void add_index_string(zval *arg, zend_ulong index, const char *str);
592 ZEND_API void add_index_stringl(zval *arg, zend_ulong index, const char *str, size_t length);
593 ZEND_API void add_index_array(zval *arg, zend_ulong index, zend_array *arr);
594 ZEND_API void add_index_object(zval *arg, zend_ulong index, zend_object *obj);
595 ZEND_API void add_index_reference(zval *arg, zend_ulong index, zend_reference *ref);
596 
add_index_zval(zval * arg,zend_ulong index,zval * value)597 static zend_always_inline zend_result add_index_zval(zval *arg, zend_ulong index, zval *value)
598 {
599 	return zend_hash_index_update(Z_ARRVAL_P(arg), index, value) ? SUCCESS : FAILURE;
600 }
601 
602 ZEND_API zend_result add_next_index_long(zval *arg, zend_long n);
603 ZEND_API zend_result add_next_index_null(zval *arg);
604 ZEND_API zend_result add_next_index_bool(zval *arg, bool b);
605 ZEND_API zend_result add_next_index_resource(zval *arg, zend_resource *r);
606 ZEND_API zend_result add_next_index_double(zval *arg, double d);
607 ZEND_API zend_result add_next_index_str(zval *arg, zend_string *str);
608 ZEND_API zend_result add_next_index_string(zval *arg, const char *str);
609 ZEND_API zend_result add_next_index_stringl(zval *arg, const char *str, size_t length);
610 ZEND_API zend_result add_next_index_array(zval *arg, zend_array *arr);
611 ZEND_API zend_result add_next_index_object(zval *arg, zend_object *obj);
612 ZEND_API zend_result add_next_index_reference(zval *arg, zend_reference *ref);
613 
add_next_index_zval(zval * arg,zval * value)614 static zend_always_inline zend_result add_next_index_zval(zval *arg, zval *value)
615 {
616 	return zend_hash_next_index_insert(Z_ARRVAL_P(arg), value) ? SUCCESS : FAILURE;
617 }
618 
619 ZEND_API zend_result array_set_zval_key(HashTable *ht, zval *key, zval *value);
620 
621 ZEND_API void add_property_long_ex(zval *arg, const char *key, size_t key_len, zend_long l);
622 ZEND_API void add_property_null_ex(zval *arg, const char *key, size_t key_len);
623 ZEND_API void add_property_bool_ex(zval *arg, const char *key, size_t key_len, zend_long b);
624 ZEND_API void add_property_resource_ex(zval *arg, const char *key, size_t key_len, zend_resource *r);
625 ZEND_API void add_property_double_ex(zval *arg, const char *key, size_t key_len, double d);
626 ZEND_API void add_property_str_ex(zval *arg, const char *key, size_t key_len, zend_string *str);
627 ZEND_API void add_property_string_ex(zval *arg, const char *key, size_t key_len, const char *str);
628 ZEND_API void add_property_stringl_ex(zval *arg, const char *key, size_t key_len,  const char *str, size_t length);
629 ZEND_API void add_property_array_ex(zval *arg, const char *key, size_t key_len, zend_array *arr);
630 ZEND_API void add_property_object_ex(zval *arg, const char *key, size_t key_len, zend_object *obj);
631 ZEND_API void add_property_reference_ex(zval *arg, const char *key, size_t key_len, zend_reference *ref);
632 ZEND_API void add_property_zval_ex(zval *arg, const char *key, size_t key_len, zval *value);
633 
add_property_long(zval * arg,const char * key,zend_long n)634 static zend_always_inline void add_property_long(zval *arg, const char *key, zend_long n) {
635 	add_property_long_ex(arg, key, strlen(key), n);
636 }
add_property_null(zval * arg,const char * key)637 static zend_always_inline void add_property_null(zval *arg, const char *key) {
638 	add_property_null_ex(arg, key, strlen(key));
639 }
add_property_bool(zval * arg,const char * key,bool b)640 static zend_always_inline void add_property_bool(zval *arg, const char *key, bool b) {
641 	add_property_bool_ex(arg, key, strlen(key), b);
642 }
add_property_resource(zval * arg,const char * key,zend_resource * r)643 static zend_always_inline void add_property_resource(zval *arg, const char *key, zend_resource *r) {
644 	add_property_resource_ex(arg, key, strlen(key), r);
645 }
add_property_double(zval * arg,const char * key,double d)646 static zend_always_inline void add_property_double(zval *arg, const char *key, double d) {
647 	add_property_double_ex(arg, key, strlen(key), d);
648 }
add_property_str(zval * arg,const char * key,zend_string * str)649 static zend_always_inline void add_property_str(zval *arg, const char *key, zend_string *str) {
650 	add_property_str_ex(arg, key, strlen(key), str);
651 }
add_property_string(zval * arg,const char * key,const char * str)652 static zend_always_inline void add_property_string(zval *arg, const char *key, const char *str) {
653 	add_property_string_ex(arg, key, strlen(key), str);
654 }
add_property_stringl(zval * arg,const char * key,const char * str,size_t length)655 static zend_always_inline void add_property_stringl(zval *arg, const char *key, const char *str, size_t length) {
656 	add_property_stringl_ex(arg, key, strlen(key), str, length);
657 }
add_property_array(zval * arg,const char * key,zend_array * arr)658 static zend_always_inline void add_property_array(zval *arg, const char *key, zend_array *arr) {
659 	add_property_array_ex(arg, key, strlen(key), arr);
660 }
add_property_object(zval * arg,const char * key,zend_object * obj)661 static zend_always_inline void add_property_object(zval *arg, const char *key, zend_object *obj) {
662 	add_property_object_ex(arg, key, strlen(key), obj);
663 }
add_property_reference(zval * arg,const char * key,zend_reference * ref)664 static zend_always_inline void add_property_reference(zval *arg, const char *key, zend_reference *ref) {
665 	add_property_reference_ex(arg, key, strlen(key), ref);
666 }
add_property_zval(zval * arg,const char * key,zval * value)667 static zend_always_inline void add_property_zval(zval *arg, const char *key, zval *value) {
668 	add_property_zval_ex(arg, key, strlen(key), value);
669 }
670 
671 ZEND_API zend_result _call_user_function_impl(zval *object, zval *function_name, zval *retval_ptr, uint32_t param_count, zval params[], HashTable *named_params);
672 
673 #define call_user_function(function_table, object, function_name, retval_ptr, param_count, params) \
674 	_call_user_function_impl(object, function_name, retval_ptr, param_count, params, NULL)
675 
676 #define call_user_function_named(function_table, object, function_name, retval_ptr, param_count, params, named_params) \
677 	_call_user_function_impl(object, function_name, retval_ptr, param_count, params, named_params)
678 
679 ZEND_API extern const zend_fcall_info empty_fcall_info;
680 ZEND_API extern const zend_fcall_info_cache empty_fcall_info_cache;
681 
682 /** Build zend_call_info/cache from a zval*
683  *
684  * Caller is responsible to provide a return value (fci->retval), otherwise the we will crash.
685  * In order to pass parameters the following members need to be set:
686  * fci->param_count = 0;
687  * fci->params = NULL;
688  * The callable_name argument may be NULL.
689  */
690 ZEND_API zend_result zend_fcall_info_init(zval *callable, uint32_t check_flags, zend_fcall_info *fci, zend_fcall_info_cache *fcc, zend_string **callable_name, char **error);
691 
692 /** Clear arguments connected with zend_fcall_info *fci
693  * If free_mem is not zero then the params array gets free'd as well
694  */
695 ZEND_API void zend_fcall_info_args_clear(zend_fcall_info *fci, bool free_mem);
696 
697 /** Save current arguments from zend_fcall_info *fci
698  * params array will be set to NULL
699  */
700 ZEND_API void zend_fcall_info_args_save(zend_fcall_info *fci, uint32_t *param_count, zval **params);
701 
702 /** Free arguments connected with zend_fcall_info *fci and set back saved ones.
703  */
704 ZEND_API void zend_fcall_info_args_restore(zend_fcall_info *fci, uint32_t param_count, zval *params);
705 
706 /** Set or clear the arguments in the zend_call_info struct taking care of
707  * refcount. If args is NULL and arguments are set then those are cleared.
708  */
709 ZEND_API zend_result zend_fcall_info_args(zend_fcall_info *fci, zval *args);
710 ZEND_API zend_result zend_fcall_info_args_ex(zend_fcall_info *fci, zend_function *func, zval *args);
711 
712 /** Set arguments in the zend_fcall_info struct taking care of refcount.
713  * If argc is 0 the arguments which are set will be cleared, else pass
714  * a variable amount of zval** arguments.
715  */
716 ZEND_API void zend_fcall_info_argp(zend_fcall_info *fci, uint32_t argc, zval *argv);
717 
718 /** Set arguments in the zend_fcall_info struct taking care of refcount.
719  * If argc is 0 the arguments which are set will be cleared, else pass
720  * a variable amount of zval** arguments.
721  */
722 ZEND_API void zend_fcall_info_argv(zend_fcall_info *fci, uint32_t argc, va_list *argv);
723 
724 /** Set arguments in the zend_fcall_info struct taking care of refcount.
725  * If argc is 0 the arguments which are set will be cleared, else pass
726  * a variable amount of zval** arguments.
727  */
728 ZEND_API void zend_fcall_info_argn(zend_fcall_info *fci, uint32_t argc, ...);
729 
730 /** Call a function using information created by zend_fcall_info_init()/args().
731  * If args is given then those replace the argument info in fci is temporarily.
732  */
733 ZEND_API zend_result zend_fcall_info_call(zend_fcall_info *fci, zend_fcall_info_cache *fcc, zval *retval, zval *args);
734 
735 /* Can only return FAILURE if EG(active) is false during late engine shutdown.
736  * If the call or call setup throws, EG(exception) will be set and the retval
737  * will be UNDEF. Otherwise, the retval will be a non-UNDEF value. */
738 ZEND_API zend_result zend_call_function(zend_fcall_info *fci, zend_fcall_info_cache *fci_cache);
739 
740 /* Call the provided zend_function with the given params.
741  * If retval_ptr is NULL, the return value is discarded.
742  * If object is NULL, this must be a free function or static call.
743  * called_scope must be provided for instance and static method calls. */
744 ZEND_API void zend_call_known_function(
745 		zend_function *fn, zend_object *object, zend_class_entry *called_scope, zval *retval_ptr,
746 		uint32_t param_count, zval *params, HashTable *named_params);
747 
748 /* Call the provided zend_function instance method on an object. */
zend_call_known_instance_method(zend_function * fn,zend_object * object,zval * retval_ptr,uint32_t param_count,zval * params)749 static zend_always_inline void zend_call_known_instance_method(
750 		zend_function *fn, zend_object *object, zval *retval_ptr,
751 		uint32_t param_count, zval *params)
752 {
753 	zend_call_known_function(fn, object, object->ce, retval_ptr, param_count, params, NULL);
754 }
755 
zend_call_known_instance_method_with_0_params(zend_function * fn,zend_object * object,zval * retval_ptr)756 static zend_always_inline void zend_call_known_instance_method_with_0_params(
757 		zend_function *fn, zend_object *object, zval *retval_ptr)
758 {
759 	zend_call_known_instance_method(fn, object, retval_ptr, 0, NULL);
760 }
761 
zend_call_known_instance_method_with_1_params(zend_function * fn,zend_object * object,zval * retval_ptr,zval * param)762 static zend_always_inline void zend_call_known_instance_method_with_1_params(
763 		zend_function *fn, zend_object *object, zval *retval_ptr, zval *param)
764 {
765 	zend_call_known_instance_method(fn, object, retval_ptr, 1, param);
766 }
767 
768 ZEND_API void zend_call_known_instance_method_with_2_params(
769 		zend_function *fn, zend_object *object, zval *retval_ptr, zval *param1, zval *param2);
770 
771 /* Call method if it exists. Return FAILURE if method does not exist or call failed.
772  * If FAILURE is returned, retval will be UNDEF. As such, destroying retval unconditionally
773  * is legal. */
774 ZEND_API zend_result zend_call_method_if_exists(
775 		zend_object *object, zend_string *method_name, zval *retval,
776 		uint32_t param_count, zval *params);
777 
778 ZEND_API zend_result zend_set_hash_symbol(zval *symbol, const char *name, size_t name_length, bool is_ref, int num_symbol_tables, ...);
779 
780 ZEND_API zend_result zend_delete_global_variable(zend_string *name);
781 
782 ZEND_API zend_array *zend_rebuild_symbol_table(void);
783 ZEND_API void zend_attach_symbol_table(zend_execute_data *execute_data);
784 ZEND_API void zend_detach_symbol_table(zend_execute_data *execute_data);
785 ZEND_API zend_result zend_set_local_var(zend_string *name, zval *value, bool force);
786 ZEND_API zend_result zend_set_local_var_str(const char *name, size_t len, zval *value, bool force);
787 
zend_forbid_dynamic_call(void)788 static zend_always_inline zend_result zend_forbid_dynamic_call(void)
789 {
790 	zend_execute_data *ex = EG(current_execute_data);
791 	ZEND_ASSERT(ex != NULL && ex->func != NULL);
792 
793 	if (ZEND_CALL_INFO(ex) & ZEND_CALL_DYNAMIC) {
794 		zend_string *function_or_method_name = get_active_function_or_method_name();
795 		zend_throw_error(NULL, "Cannot call %.*s() dynamically",
796 			(int) ZSTR_LEN(function_or_method_name), ZSTR_VAL(function_or_method_name));
797 		zend_string_release(function_or_method_name);
798 		return FAILURE;
799 	}
800 
801 	return SUCCESS;
802 }
803 
804 ZEND_API ZEND_COLD const char *zend_get_object_type_case(const zend_class_entry *ce, bool upper_case);
805 
zend_get_object_type(const zend_class_entry * ce)806 static zend_always_inline const char *zend_get_object_type(const zend_class_entry *ce)
807 {
808 	return zend_get_object_type_case(ce, false);
809 }
810 
zend_get_object_type_uc(const zend_class_entry * ce)811 static zend_always_inline const char *zend_get_object_type_uc(const zend_class_entry *ce)
812 {
813 	return zend_get_object_type_case(ce, true);
814 }
815 
816 ZEND_API bool zend_is_iterable(zval *iterable);
817 
818 ZEND_API bool zend_is_countable(zval *countable);
819 
820 ZEND_API zend_result zend_get_default_from_internal_arg_info(
821 		zval *default_value_zval, zend_internal_arg_info *arg_info);
822 
END_EXTERN_C()823 END_EXTERN_C()
824 
825 #if ZEND_DEBUG
826 #define CHECK_ZVAL_STRING(str) \
827 	ZEND_ASSERT(ZSTR_VAL(str)[ZSTR_LEN(str)] == '\0' && "String is not null-terminated");
828 #else
829 #define CHECK_ZVAL_STRING(z)
830 #endif
831 
832 static zend_always_inline bool zend_str_has_nul_byte(const zend_string *str)
833 {
834 	return ZSTR_LEN(str) != strlen(ZSTR_VAL(str));
835 }
zend_char_has_nul_byte(const char * s,size_t known_length)836 static zend_always_inline bool zend_char_has_nul_byte(const char *s, size_t known_length)
837 {
838 	return known_length != strlen(s);
839 }
840 
841 /* Compatibility with PHP 8.1 and below */
842 #define CHECK_ZVAL_NULL_PATH(p) zend_str_has_nul_byte(Z_STR_P(p))
843 #define CHECK_NULL_PATH(p, l) zend_char_has_nul_byte(p, l)
844 
845 #define ZVAL_STRINGL(z, s, l) do {				\
846 		ZVAL_NEW_STR(z, zend_string_init(s, l, 0));		\
847 	} while (0)
848 
849 #define ZVAL_STRING(z, s) do {					\
850 		const char *_s = (s);					\
851 		ZVAL_STRINGL(z, _s, strlen(_s));		\
852 	} while (0)
853 
854 #define ZVAL_EMPTY_STRING(z) do {				\
855 		ZVAL_INTERNED_STR(z, ZSTR_EMPTY_ALLOC());		\
856 	} while (0)
857 
858 #define ZVAL_PSTRINGL(z, s, l) do {				\
859 		ZVAL_NEW_STR(z, zend_string_init(s, l, 1));		\
860 	} while (0)
861 
862 #define ZVAL_PSTRING(z, s) do {					\
863 		const char *_s = (s);					\
864 		ZVAL_PSTRINGL(z, _s, strlen(_s));		\
865 	} while (0)
866 
867 #define ZVAL_EMPTY_PSTRING(z) do {				\
868 		ZVAL_PSTRINGL(z, "", 0);				\
869 	} while (0)
870 
871 #define ZVAL_CHAR(z, c)  do {		            \
872 		char _c = (c);                          \
873 		ZVAL_INTERNED_STR(z, ZSTR_CHAR((zend_uchar) _c));	\
874 	} while (0)
875 
876 #define ZVAL_STRINGL_FAST(z, s, l) do {			\
877 		ZVAL_STR(z, zend_string_init_fast(s, l));	\
878 	} while (0)
879 
880 #define ZVAL_STRING_FAST(z, s) do {				\
881 		const char *_s = (s);					\
882 		ZVAL_STRINGL_FAST(z, _s, strlen(_s));	\
883 	} while (0)
884 
885 #define ZVAL_ZVAL(z, zv, copy, dtor) do {		\
886 		zval *__z = (z);						\
887 		zval *__zv = (zv);						\
888 		if (EXPECTED(!Z_ISREF_P(__zv))) {		\
889 			if (copy && !dtor) {				\
890 				ZVAL_COPY(__z, __zv);			\
891 			} else {							\
892 				ZVAL_COPY_VALUE(__z, __zv);		\
893 			}									\
894 		} else {								\
895 			ZVAL_COPY(__z, Z_REFVAL_P(__zv));	\
896 			if (dtor || !copy) {				\
897 				zval_ptr_dtor(__zv);			\
898 			}									\
899 		}										\
900 	} while (0)
901 
902 #define RETVAL_BOOL(b)					ZVAL_BOOL(return_value, b)
903 #define RETVAL_NULL()					ZVAL_NULL(return_value)
904 #define RETVAL_LONG(l)					ZVAL_LONG(return_value, l)
905 #define RETVAL_DOUBLE(d)				ZVAL_DOUBLE(return_value, d)
906 #define RETVAL_STR(s)					ZVAL_STR(return_value, s)
907 #define RETVAL_INTERNED_STR(s)			ZVAL_INTERNED_STR(return_value, s)
908 #define RETVAL_NEW_STR(s)				ZVAL_NEW_STR(return_value, s)
909 #define RETVAL_STR_COPY(s)				ZVAL_STR_COPY(return_value, s)
910 #define RETVAL_STRING(s)				ZVAL_STRING(return_value, s)
911 #define RETVAL_STRINGL(s, l)			ZVAL_STRINGL(return_value, s, l)
912 #define RETVAL_STRING_FAST(s)			ZVAL_STRING_FAST(return_value, s)
913 #define RETVAL_STRINGL_FAST(s, l)		ZVAL_STRINGL_FAST(return_value, s, l)
914 #define RETVAL_EMPTY_STRING()			ZVAL_EMPTY_STRING(return_value)
915 #define RETVAL_CHAR(c)		            ZVAL_CHAR(return_value, c)
916 #define RETVAL_RES(r)					ZVAL_RES(return_value, r)
917 #define RETVAL_ARR(r)					ZVAL_ARR(return_value, r)
918 #define RETVAL_EMPTY_ARRAY()			ZVAL_EMPTY_ARRAY(return_value)
919 #define RETVAL_OBJ(r)					ZVAL_OBJ(return_value, r)
920 #define RETVAL_OBJ_COPY(r)				ZVAL_OBJ_COPY(return_value, r)
921 #define RETVAL_COPY(zv)					ZVAL_COPY(return_value, zv)
922 #define RETVAL_COPY_VALUE(zv)			ZVAL_COPY_VALUE(return_value, zv)
923 #define RETVAL_COPY_DEREF(zv)			ZVAL_COPY_DEREF(return_value, zv)
924 #define RETVAL_ZVAL(zv, copy, dtor)		ZVAL_ZVAL(return_value, zv, copy, dtor)
925 #define RETVAL_FALSE					ZVAL_FALSE(return_value)
926 #define RETVAL_TRUE						ZVAL_TRUE(return_value)
927 
928 #define RETURN_BOOL(b)					do { RETVAL_BOOL(b); return; } while (0)
929 #define RETURN_NULL()					do { RETVAL_NULL(); return;} while (0)
930 #define RETURN_LONG(l)					do { RETVAL_LONG(l); return; } while (0)
931 #define RETURN_DOUBLE(d)				do { RETVAL_DOUBLE(d); return; } while (0)
932 #define RETURN_STR(s) 					do { RETVAL_STR(s); return; } while (0)
933 #define RETURN_INTERNED_STR(s)			do { RETVAL_INTERNED_STR(s); return; } while (0)
934 #define RETURN_NEW_STR(s)				do { RETVAL_NEW_STR(s); return; } while (0)
935 #define RETURN_STR_COPY(s)				do { RETVAL_STR_COPY(s); return; } while (0)
936 #define RETURN_STRING(s) 				do { RETVAL_STRING(s); return; } while (0)
937 #define RETURN_STRINGL(s, l) 			do { RETVAL_STRINGL(s, l); return; } while (0)
938 #define RETURN_STRING_FAST(s) 			do { RETVAL_STRING_FAST(s); return; } while (0)
939 #define RETURN_STRINGL_FAST(s, l)		do { RETVAL_STRINGL_FAST(s, l); return; } while (0)
940 #define RETURN_EMPTY_STRING() 			do { RETVAL_EMPTY_STRING(); return; } while (0)
941 #define RETURN_CHAR(c)		            do { RETVAL_CHAR(c); return; } while (0)
942 #define RETURN_RES(r)					do { RETVAL_RES(r); return; } while (0)
943 #define RETURN_ARR(r)					do { RETVAL_ARR(r); return; } while (0)
944 #define RETURN_EMPTY_ARRAY()			do { RETVAL_EMPTY_ARRAY(); return; } while (0)
945 #define RETURN_OBJ(r)					do { RETVAL_OBJ(r); return; } while (0)
946 #define RETURN_OBJ_COPY(r)				do { RETVAL_OBJ_COPY(r); return; } while (0)
947 #define RETURN_COPY(zv)					do { RETVAL_COPY(zv); return; } while (0)
948 #define RETURN_COPY_VALUE(zv)			do { RETVAL_COPY_VALUE(zv); return; } while (0)
949 #define RETURN_COPY_DEREF(zv)			do { RETVAL_COPY_DEREF(zv); return; } while (0)
950 #define RETURN_ZVAL(zv, copy, dtor)		do { RETVAL_ZVAL(zv, copy, dtor); return; } while (0)
951 #define RETURN_FALSE					do { RETVAL_FALSE; return; } while (0)
952 #define RETURN_TRUE						do { RETVAL_TRUE; return; } while (0)
953 #define RETURN_THROWS()					do { ZEND_ASSERT(EG(exception)); (void) return_value; return; } while (0)
954 
955 #define HASH_OF(p) (Z_TYPE_P(p)==IS_ARRAY ? Z_ARRVAL_P(p) : ((Z_TYPE_P(p)==IS_OBJECT ? Z_OBJ_HT_P(p)->get_properties(Z_OBJ_P(p)) : NULL)))
956 #define ZVAL_IS_NULL(z) (Z_TYPE_P(z) == IS_NULL)
957 
958 /* For compatibility */
959 #define ZEND_MINIT			ZEND_MODULE_STARTUP_N
960 #define ZEND_MSHUTDOWN		ZEND_MODULE_SHUTDOWN_N
961 #define ZEND_RINIT			ZEND_MODULE_ACTIVATE_N
962 #define ZEND_RSHUTDOWN		ZEND_MODULE_DEACTIVATE_N
963 #define ZEND_MINFO			ZEND_MODULE_INFO_N
964 #define ZEND_GINIT(module)		((void (*)(void*))(ZEND_MODULE_GLOBALS_CTOR_N(module)))
965 #define ZEND_GSHUTDOWN(module)	((void (*)(void*))(ZEND_MODULE_GLOBALS_DTOR_N(module)))
966 
967 #define ZEND_MINIT_FUNCTION			ZEND_MODULE_STARTUP_D
968 #define ZEND_MSHUTDOWN_FUNCTION		ZEND_MODULE_SHUTDOWN_D
969 #define ZEND_RINIT_FUNCTION			ZEND_MODULE_ACTIVATE_D
970 #define ZEND_RSHUTDOWN_FUNCTION		ZEND_MODULE_DEACTIVATE_D
971 #define ZEND_MINFO_FUNCTION			ZEND_MODULE_INFO_D
972 #define ZEND_GINIT_FUNCTION			ZEND_MODULE_GLOBALS_CTOR_D
973 #define ZEND_GSHUTDOWN_FUNCTION		ZEND_MODULE_GLOBALS_DTOR_D
974 
975 /* May modify arg in-place. Will free arg in failure case (and take ownership in success case).
976  * Prefer using the ZEND_TRY_ASSIGN_* macros over these APIs. */
977 ZEND_API zend_result zend_try_assign_typed_ref_ex(zend_reference *ref, zval *zv, bool strict);
978 ZEND_API zend_result zend_try_assign_typed_ref(zend_reference *ref, zval *zv);
979 
980 ZEND_API zend_result zend_try_assign_typed_ref_null(zend_reference *ref);
981 ZEND_API zend_result zend_try_assign_typed_ref_bool(zend_reference *ref, bool val);
982 ZEND_API zend_result zend_try_assign_typed_ref_long(zend_reference *ref, zend_long lval);
983 ZEND_API zend_result zend_try_assign_typed_ref_double(zend_reference *ref, double dval);
984 ZEND_API zend_result zend_try_assign_typed_ref_empty_string(zend_reference *ref);
985 ZEND_API zend_result zend_try_assign_typed_ref_str(zend_reference *ref, zend_string *str);
986 ZEND_API zend_result zend_try_assign_typed_ref_string(zend_reference *ref, const char *string);
987 ZEND_API zend_result zend_try_assign_typed_ref_stringl(zend_reference *ref, const char *string, size_t len);
988 ZEND_API zend_result zend_try_assign_typed_ref_arr(zend_reference *ref, zend_array *arr);
989 ZEND_API zend_result zend_try_assign_typed_ref_res(zend_reference *ref, zend_resource *res);
990 ZEND_API zend_result zend_try_assign_typed_ref_zval(zend_reference *ref, zval *zv);
991 ZEND_API zend_result zend_try_assign_typed_ref_zval_ex(zend_reference *ref, zval *zv, bool strict);
992 
993 #define _ZEND_TRY_ASSIGN_NULL(zv, is_ref) do { \
994 	zval *_zv = zv; \
995 	if (is_ref || UNEXPECTED(Z_ISREF_P(_zv))) { \
996 		zend_reference *ref = Z_REF_P(_zv); \
997 		if (UNEXPECTED(ZEND_REF_HAS_TYPE_SOURCES(ref))) { \
998 			zend_try_assign_typed_ref_null(ref); \
999 			break; \
1000 		} \
1001 		_zv = &ref->val; \
1002 	} \
1003 	zval_ptr_dtor(_zv); \
1004 	ZVAL_NULL(_zv); \
1005 } while (0)
1006 
1007 #define ZEND_TRY_ASSIGN_NULL(zv) \
1008 	_ZEND_TRY_ASSIGN_NULL(zv, 0)
1009 
1010 #define ZEND_TRY_ASSIGN_REF_NULL(zv) do { \
1011 	ZEND_ASSERT(Z_ISREF_P(zv)); \
1012 	_ZEND_TRY_ASSIGN_NULL(zv, 1); \
1013 } while (0)
1014 
1015 #define _ZEND_TRY_ASSIGN_FALSE(zv, is_ref) do { \
1016 	zval *_zv = zv; \
1017 	if (is_ref || UNEXPECTED(Z_ISREF_P(_zv))) { \
1018 		zend_reference *ref = Z_REF_P(_zv); \
1019 		if (UNEXPECTED(ZEND_REF_HAS_TYPE_SOURCES(ref))) { \
1020 			zend_try_assign_typed_ref_bool(ref, 0); \
1021 			break; \
1022 		} \
1023 		_zv = &ref->val; \
1024 	} \
1025 	zval_ptr_dtor(_zv); \
1026 	ZVAL_FALSE(_zv); \
1027 } while (0)
1028 
1029 #define ZEND_TRY_ASSIGN_FALSE(zv) \
1030 	_ZEND_TRY_ASSIGN_FALSE(zv, 0)
1031 
1032 #define ZEND_TRY_ASSIGN_REF_FALSE(zv) do { \
1033 	ZEND_ASSERT(Z_ISREF_P(zv)); \
1034 	_ZEND_TRY_ASSIGN_FALSE(zv, 1); \
1035 } while (0)
1036 
1037 #define _ZEND_TRY_ASSIGN_TRUE(zv, is_ref) do { \
1038 	zval *_zv = zv; \
1039 	if (is_ref || UNEXPECTED(Z_ISREF_P(_zv))) { \
1040 		zend_reference *ref = Z_REF_P(_zv); \
1041 		if (UNEXPECTED(ZEND_REF_HAS_TYPE_SOURCES(ref))) { \
1042 			zend_try_assign_typed_ref_bool(ref, 1); \
1043 			break; \
1044 		} \
1045 		_zv = &ref->val; \
1046 	} \
1047 	zval_ptr_dtor(_zv); \
1048 	ZVAL_TRUE(_zv); \
1049 } while (0)
1050 
1051 #define ZEND_TRY_ASSIGN_TRUE(zv) \
1052 	_ZEND_TRY_ASSIGN_TRUE(zv, 0)
1053 
1054 #define ZEND_TRY_ASSIGN_REF_TRUE(zv) do { \
1055 	ZEND_ASSERT(Z_ISREF_P(zv)); \
1056 	_ZEND_TRY_ASSIGN_TRUE(zv, 1); \
1057 } while (0)
1058 
1059 #define _ZEND_TRY_ASSIGN_BOOL(zv, bval, is_ref) do { \
1060 	zval *_zv = zv; \
1061 	if (is_ref || UNEXPECTED(Z_ISREF_P(_zv))) { \
1062 		zend_reference *ref = Z_REF_P(_zv); \
1063 		if (UNEXPECTED(ZEND_REF_HAS_TYPE_SOURCES(ref))) { \
1064 			zend_try_assign_typed_ref_bool(ref, 1); \
1065 			break; \
1066 		} \
1067 		_zv = &ref->val; \
1068 	} \
1069 	zval_ptr_dtor(_zv); \
1070 	ZVAL_BOOL(_zv, bval); \
1071 } while (0)
1072 
1073 #define ZEND_TRY_ASSIGN_BOOL(zv, bval) \
1074 	_ZEND_TRY_ASSIGN_BOOL(zv, bval, 0)
1075 
1076 #define ZEND_TRY_ASSIGN_REF_BOOL(zv, bval) do { \
1077 	ZEND_ASSERT(Z_ISREF_P(zv)); \
1078 	_ZEND_TRY_ASSIGN_BOOL(zv, bval, 1); \
1079 } while (0)
1080 
1081 #define _ZEND_TRY_ASSIGN_LONG(zv, lval, is_ref) do { \
1082 	zval *_zv = zv; \
1083 	if (is_ref || UNEXPECTED(Z_ISREF_P(_zv))) { \
1084 		zend_reference *ref = Z_REF_P(_zv); \
1085 		if (UNEXPECTED(ZEND_REF_HAS_TYPE_SOURCES(ref))) { \
1086 			zend_try_assign_typed_ref_long(ref, lval); \
1087 			break; \
1088 		} \
1089 		_zv = &ref->val; \
1090 	} \
1091 	zval_ptr_dtor(_zv); \
1092 	ZVAL_LONG(_zv, lval); \
1093 } while (0)
1094 
1095 #define ZEND_TRY_ASSIGN_LONG(zv, lval) \
1096 	_ZEND_TRY_ASSIGN_LONG(zv, lval, 0)
1097 
1098 #define ZEND_TRY_ASSIGN_REF_LONG(zv, lval) do { \
1099 	ZEND_ASSERT(Z_ISREF_P(zv)); \
1100 	_ZEND_TRY_ASSIGN_LONG(zv, lval, 1); \
1101 } while (0)
1102 
1103 #define _ZEND_TRY_ASSIGN_DOUBLE(zv, dval, is_ref) do { \
1104 	zval *_zv = zv; \
1105 	if (is_ref || UNEXPECTED(Z_ISREF_P(_zv))) { \
1106 		zend_reference *ref = Z_REF_P(_zv); \
1107 		if (UNEXPECTED(ZEND_REF_HAS_TYPE_SOURCES(ref))) { \
1108 			zend_try_assign_typed_ref_double(ref, dval); \
1109 			break; \
1110 		} \
1111 		_zv = &ref->val; \
1112 	} \
1113 	zval_ptr_dtor(_zv); \
1114 	ZVAL_DOUBLE(_zv, dval); \
1115 } while (0)
1116 
1117 #define ZEND_TRY_ASSIGN_DOUBLE(zv, dval) \
1118 	_ZEND_TRY_ASSIGN_DOUBLE(zv, dval, 0)
1119 
1120 #define ZEND_TRY_ASSIGN_REF_DOUBLE(zv, dval) do { \
1121 	ZEND_ASSERT(Z_ISREF_P(zv)); \
1122 	_ZEND_TRY_ASSIGN_DOUBLE(zv, dval, 1); \
1123 } while (0)
1124 
1125 #define _ZEND_TRY_ASSIGN_EMPTY_STRING(zv, is_ref) do { \
1126 	zval *_zv = zv; \
1127 	if (is_ref || UNEXPECTED(Z_ISREF_P(_zv))) { \
1128 		zend_reference *ref = Z_REF_P(_zv); \
1129 		if (UNEXPECTED(ZEND_REF_HAS_TYPE_SOURCES(ref))) { \
1130 			zend_try_assign_typed_ref_empty_string(ref); \
1131 			break; \
1132 		} \
1133 		_zv = &ref->val; \
1134 	} \
1135 	zval_ptr_dtor(_zv); \
1136 	ZVAL_EMPTY_STRING(_zv); \
1137 } while (0)
1138 
1139 #define ZEND_TRY_ASSIGN_EMPTY_STRING(zv) \
1140 	_ZEND_TRY_ASSIGN_EMPTY_STRING(zv, 0)
1141 
1142 #define ZEND_TRY_ASSIGN_REF_EMPTY_STRING(zv) do { \
1143 	ZEND_ASSERT(Z_ISREF_P(zv)); \
1144 	_ZEND_TRY_ASSIGN_EMPTY_STRING(zv, 1); \
1145 } while (0)
1146 
1147 #define _ZEND_TRY_ASSIGN_STR(zv, str, is_ref) do { \
1148 	zval *_zv = zv; \
1149 	if (is_ref || UNEXPECTED(Z_ISREF_P(_zv))) { \
1150 		zend_reference *ref = Z_REF_P(_zv); \
1151 		if (UNEXPECTED(ZEND_REF_HAS_TYPE_SOURCES(ref))) { \
1152 			zend_try_assign_typed_ref_str(ref, str); \
1153 			break; \
1154 		} \
1155 		_zv = &ref->val; \
1156 	} \
1157 	zval_ptr_dtor(_zv); \
1158 	ZVAL_STR(_zv, str); \
1159 } while (0)
1160 
1161 #define ZEND_TRY_ASSIGN_STR(zv, str) \
1162 	_ZEND_TRY_ASSIGN_STR(zv, str, 0)
1163 
1164 #define ZEND_TRY_ASSIGN_REF_STR(zv, str) do { \
1165 	ZEND_ASSERT(Z_ISREF_P(zv)); \
1166 	_ZEND_TRY_ASSIGN_STR(zv, str, 1); \
1167 } while (0)
1168 
1169 #define _ZEND_TRY_ASSIGN_NEW_STR(zv, str, is_str) do { \
1170 	zval *_zv = zv; \
1171 	if (is_str || UNEXPECTED(Z_ISREF_P(_zv))) { \
1172 		zend_reference *ref = Z_REF_P(_zv); \
1173 		if (UNEXPECTED(ZEND_REF_HAS_TYPE_SOURCES(ref))) { \
1174 			zend_try_assign_typed_ref_str(ref, str); \
1175 			break; \
1176 		} \
1177 		_zv = &ref->val; \
1178 	} \
1179 	zval_ptr_dtor(_zv); \
1180 	ZVAL_NEW_STR(_zv, str); \
1181 } while (0)
1182 
1183 #define ZEND_TRY_ASSIGN_NEW_STR(zv, str) \
1184 	_ZEND_TRY_ASSIGN_NEW_STR(zv, str, 0)
1185 
1186 #define ZEND_TRY_ASSIGN_REF_NEW_STR(zv, str) do { \
1187 	ZEND_ASSERT(Z_ISREF_P(zv)); \
1188 	_ZEND_TRY_ASSIGN_NEW_STR(zv, str, 1); \
1189 } while (0)
1190 
1191 #define _ZEND_TRY_ASSIGN_STRING(zv, string, is_ref) do { \
1192 	zval *_zv = zv; \
1193 	if (is_ref || UNEXPECTED(Z_ISREF_P(_zv))) { \
1194 		zend_reference *ref = Z_REF_P(_zv); \
1195 		if (UNEXPECTED(ZEND_REF_HAS_TYPE_SOURCES(ref))) { \
1196 			zend_try_assign_typed_ref_string(ref, string); \
1197 			break; \
1198 		} \
1199 		_zv = &ref->val; \
1200 	} \
1201 	zval_ptr_dtor(_zv); \
1202 	ZVAL_STRING(_zv, string); \
1203 } while (0)
1204 
1205 #define ZEND_TRY_ASSIGN_STRING(zv, string) \
1206 	_ZEND_TRY_ASSIGN_STRING(zv, string, 0)
1207 
1208 #define ZEND_TRY_ASSIGN_REF_STRING(zv, string) do { \
1209 	ZEND_ASSERT(Z_ISREF_P(zv)); \
1210 	_ZEND_TRY_ASSIGN_STRING(zv, string, 1); \
1211 } while (0)
1212 
1213 #define _ZEND_TRY_ASSIGN_STRINGL(zv, string, len, is_ref) do { \
1214 	zval *_zv = zv; \
1215 	if (is_ref || UNEXPECTED(Z_ISREF_P(_zv))) { \
1216 		zend_reference *ref = Z_REF_P(_zv); \
1217 		if (UNEXPECTED(ZEND_REF_HAS_TYPE_SOURCES(ref))) { \
1218 			zend_try_assign_typed_ref_stringl(ref, string, len); \
1219 			break; \
1220 		} \
1221 		_zv = &ref->val; \
1222 	} \
1223 	zval_ptr_dtor(_zv); \
1224 	ZVAL_STRINGL(_zv, string, len); \
1225 } while (0)
1226 
1227 #define ZEND_TRY_ASSIGN_STRINGL(zv, string, len) \
1228 	_ZEND_TRY_ASSIGN_STRINGL(zv, string, len, 0)
1229 
1230 #define ZEND_TRY_ASSIGN_REF_STRINGL(zv, string, len) do { \
1231 	ZEND_ASSERT(Z_ISREF_P(zv)); \
1232 	_ZEND_TRY_ASSIGN_STRINGL(zv, string, len, 1); \
1233 } while (0)
1234 
1235 #define _ZEND_TRY_ASSIGN_ARR(zv, arr, is_ref) do { \
1236 	zval *_zv = zv; \
1237 	if (is_ref || UNEXPECTED(Z_ISREF_P(_zv))) { \
1238 		zend_reference *ref = Z_REF_P(_zv); \
1239 		if (UNEXPECTED(ZEND_REF_HAS_TYPE_SOURCES(ref))) { \
1240 			zend_try_assign_typed_ref_arr(ref, arr); \
1241 			break; \
1242 		} \
1243 		_zv = &ref->val; \
1244 	} \
1245 	zval_ptr_dtor(_zv); \
1246 	ZVAL_ARR(_zv, arr); \
1247 } while (0)
1248 
1249 #define ZEND_TRY_ASSIGN_ARR(zv, arr) \
1250 	_ZEND_TRY_ASSIGN_ARR(zv, arr, 0)
1251 
1252 #define ZEND_TRY_ASSIGN_REF_ARR(zv, arr) do { \
1253 	ZEND_ASSERT(Z_ISREF_P(zv)); \
1254 	_ZEND_TRY_ASSIGN_ARR(zv, arr, 1); \
1255 } while (0)
1256 
1257 #define _ZEND_TRY_ASSIGN_RES(zv, res, is_ref) do { \
1258 	zval *_zv = zv; \
1259 	if (is_ref || UNEXPECTED(Z_ISREF_P(_zv))) { \
1260 		zend_reference *ref = Z_REF_P(_zv); \
1261 		if (UNEXPECTED(ZEND_REF_HAS_TYPE_SOURCES(ref))) { \
1262 			zend_try_assign_typed_ref_res(ref, res); \
1263 			break; \
1264 		} \
1265 		_zv = &ref->val; \
1266 	} \
1267 	zval_ptr_dtor(_zv); \
1268 	ZVAL_RES(_zv, res); \
1269 } while (0)
1270 
1271 #define ZEND_TRY_ASSIGN_RES(zv, res) \
1272 	_ZEND_TRY_ASSIGN_RES(zv, res, 0)
1273 
1274 #define ZEND_TRY_ASSIGN_REF_RES(zv, res) do { \
1275 	ZEND_ASSERT(Z_ISREF_P(zv)); \
1276 	_ZEND_TRY_ASSIGN_RES(zv, res, 1); \
1277 } while (0)
1278 
1279 #define _ZEND_TRY_ASSIGN_TMP(zv, other_zv, is_ref) do { \
1280 	zval *_zv = zv; \
1281 	if (is_ref || UNEXPECTED(Z_ISREF_P(_zv))) { \
1282 		zend_reference *ref = Z_REF_P(_zv); \
1283 		if (UNEXPECTED(ZEND_REF_HAS_TYPE_SOURCES(ref))) { \
1284 			zend_try_assign_typed_ref(ref, other_zv); \
1285 			break; \
1286 		} \
1287 		_zv = &ref->val; \
1288 	} \
1289 	zval_ptr_dtor(_zv); \
1290 	ZVAL_COPY_VALUE(_zv, other_zv); \
1291 } while (0)
1292 
1293 #define ZEND_TRY_ASSIGN_TMP(zv, other_zv) \
1294 	_ZEND_TRY_ASSIGN_TMP(zv, other_zv, 0)
1295 
1296 #define ZEND_TRY_ASSIGN_REF_TMP(zv, other_zv) do { \
1297 	ZEND_ASSERT(Z_ISREF_P(zv)); \
1298 	_ZEND_TRY_ASSIGN_TMP(zv, other_zv, 1); \
1299 } while (0)
1300 
1301 #define _ZEND_TRY_ASSIGN_VALUE(zv, other_zv, is_ref) do { \
1302 	zval *_zv = zv; \
1303 	if (is_ref || UNEXPECTED(Z_ISREF_P(_zv))) { \
1304 		zend_reference *ref = Z_REF_P(_zv); \
1305 		if (UNEXPECTED(ZEND_REF_HAS_TYPE_SOURCES(ref))) { \
1306 			zend_try_assign_typed_ref_zval(ref, other_zv); \
1307 			break; \
1308 		} \
1309 		_zv = &ref->val; \
1310 	} \
1311 	zval_ptr_dtor(_zv); \
1312 	ZVAL_COPY_VALUE(_zv, other_zv); \
1313 } while (0)
1314 
1315 #define ZEND_TRY_ASSIGN_VALUE(zv, other_zv) \
1316 	_ZEND_TRY_ASSIGN_VALUE(zv, other_zv, 0)
1317 
1318 #define ZEND_TRY_ASSIGN_REF_VALUE(zv, other_zv) do { \
1319 	ZEND_ASSERT(Z_ISREF_P(zv)); \
1320 	_ZEND_TRY_ASSIGN_VALUE(zv, other_zv, 1); \
1321 } while (0)
1322 
1323 #define ZEND_TRY_ASSIGN_COPY(zv, other_zv) do { \
1324 	Z_TRY_ADDREF_P(other_zv); \
1325 	ZEND_TRY_ASSIGN_VALUE(zv, other_zv); \
1326 } while (0)
1327 
1328 #define ZEND_TRY_ASSIGN_REF_COPY(zv, other_zv) do { \
1329 	Z_TRY_ADDREF_P(other_zv); \
1330 	ZEND_TRY_ASSIGN_REF_VALUE(zv, other_zv); \
1331 } while (0)
1332 
1333 #define _ZEND_TRY_ASSIGN_VALUE_EX(zv, other_zv, strict, is_ref) do { \
1334 	zval *_zv = zv; \
1335 	if (is_ref || UNEXPECTED(Z_ISREF_P(_zv))) { \
1336 		zend_reference *ref = Z_REF_P(_zv); \
1337 		if (UNEXPECTED(ZEND_REF_HAS_TYPE_SOURCES(ref))) { \
1338 			zend_try_assign_typed_ref_zval_ex(ref, other_zv, strict); \
1339 			break; \
1340 		} \
1341 		_zv = &ref->val; \
1342 	} \
1343 	zval_ptr_dtor(_zv); \
1344 	ZVAL_COPY_VALUE(_zv, other_zv); \
1345 } while (0)
1346 
1347 #define ZEND_TRY_ASSIGN_VALUE_EX(zv, other_zv, strict) \
1348 	_ZEND_TRY_ASSIGN_VALUE_EX(zv, other_zv, strict, 0)
1349 
1350 #define ZEND_TRY_ASSIGN_REF_VALUE_EX(zv, other_zv, strict) do { \
1351 	ZEND_ASSERT(Z_ISREF_P(zv)); \
1352 	_ZEND_TRY_ASSIGN_VALUE_EX(zv, other_zv, strict, 1); \
1353 } while (0)
1354 
1355 #define ZEND_TRY_ASSIGN_COPY_EX(zv, other_zv, strict) do { \
1356 	Z_TRY_ADDREF_P(other_zv); \
1357 	ZEND_TRY_ASSIGN_VALUE_EX(zv, other_zv, strict); \
1358 } while (0)
1359 
1360 #define ZEND_TRY_ASSIGN_REF_COPY_EX(zv, other_zv, strict) do { \
1361 	Z_TRY_ADDREF_P(other_zv); \
1362 	ZEND_TRY_ASSIGN_REF_VALUE_EX(zv, other_zv, strict); \
1363 } while (0)
1364 
1365 /* Initializes a reference to an empty array and returns dereferenced zval,
1366  * or NULL if the initialization failed. */
zend_try_array_init_size(zval * zv,uint32_t size)1367 static zend_always_inline zval *zend_try_array_init_size(zval *zv, uint32_t size)
1368 {
1369 	zend_array *arr = zend_new_array(size);
1370 
1371 	if (EXPECTED(Z_ISREF_P(zv))) {
1372 		zend_reference *ref = Z_REF_P(zv);
1373 		if (UNEXPECTED(ZEND_REF_HAS_TYPE_SOURCES(ref))) {
1374 			if (zend_try_assign_typed_ref_arr(ref, arr) == FAILURE) {
1375 				return NULL;
1376 			}
1377 			return &ref->val;
1378 		}
1379 		zv = &ref->val;
1380 	}
1381 	zval_ptr_dtor(zv);
1382 	ZVAL_ARR(zv, arr);
1383 	return zv;
1384 }
1385 
zend_try_array_init(zval * zv)1386 static zend_always_inline zval *zend_try_array_init(zval *zv)
1387 {
1388 	return zend_try_array_init_size(zv, 0);
1389 }
1390 
1391 /* Fast parameter parsing API */
1392 
1393 /* Fast ZPP is always enabled now; this define is left in for compatibility
1394  * with any existing conditional compilation blocks.
1395  */
1396 #define FAST_ZPP 1
1397 
1398 #define Z_EXPECTED_TYPES(_) \
1399 	_(Z_EXPECTED_LONG,				"of type int") \
1400 	_(Z_EXPECTED_LONG_OR_NULL,		"of type ?int") \
1401 	_(Z_EXPECTED_BOOL,				"of type bool") \
1402 	_(Z_EXPECTED_BOOL_OR_NULL,		"of type ?bool") \
1403 	_(Z_EXPECTED_STRING,			"of type string") \
1404 	_(Z_EXPECTED_STRING_OR_NULL,	"of type ?string") \
1405 	_(Z_EXPECTED_ARRAY,				"of type array") \
1406 	_(Z_EXPECTED_ARRAY_OR_NULL,		"of type ?array") \
1407 	_(Z_EXPECTED_ARRAY_OR_LONG,		"of type array|int") \
1408 	_(Z_EXPECTED_ARRAY_OR_LONG_OR_NULL, "of type array|int|null") \
1409 	_(Z_EXPECTED_ITERABLE,				"of type Traversable|array") \
1410 	_(Z_EXPECTED_ITERABLE_OR_NULL,		"of type Traversable|array|null") \
1411 	_(Z_EXPECTED_FUNC,				"a valid callback") \
1412 	_(Z_EXPECTED_FUNC_OR_NULL,		"a valid callback or null") \
1413 	_(Z_EXPECTED_RESOURCE,			"of type resource") \
1414 	_(Z_EXPECTED_RESOURCE_OR_NULL,	"of type resource or null") \
1415 	_(Z_EXPECTED_PATH,				"of type string") \
1416 	_(Z_EXPECTED_PATH_OR_NULL,		"of type ?string") \
1417 	_(Z_EXPECTED_OBJECT,			"of type object") \
1418 	_(Z_EXPECTED_OBJECT_OR_NULL,	"of type ?object") \
1419 	_(Z_EXPECTED_DOUBLE,			"of type float") \
1420 	_(Z_EXPECTED_DOUBLE_OR_NULL,	"of type ?float") \
1421 	_(Z_EXPECTED_NUMBER,			"of type int|float") \
1422 	_(Z_EXPECTED_NUMBER_OR_NULL,	"of type int|float|null") \
1423 	_(Z_EXPECTED_ARRAY_OR_STRING,	"of type array|string") \
1424 	_(Z_EXPECTED_ARRAY_OR_STRING_OR_NULL, "of type array|string|null") \
1425 	_(Z_EXPECTED_STRING_OR_LONG,	"of type string|int") \
1426 	_(Z_EXPECTED_STRING_OR_LONG_OR_NULL, "of type string|int|null") \
1427 	_(Z_EXPECTED_OBJECT_OR_CLASS_NAME,	"an object or a valid class name") \
1428 	_(Z_EXPECTED_OBJECT_OR_CLASS_NAME_OR_NULL, "an object, a valid class name, or null") \
1429 	_(Z_EXPECTED_OBJECT_OR_STRING,	"of type object|string") \
1430 	_(Z_EXPECTED_OBJECT_OR_STRING_OR_NULL, "of type object|string|null") \
1431 
1432 #define Z_EXPECTED_TYPE
1433 
1434 #define Z_EXPECTED_TYPE_ENUM(id, str) id,
1435 #define Z_EXPECTED_TYPE_STR(id, str)  str,
1436 
1437 typedef enum _zend_expected_type {
1438 	Z_EXPECTED_TYPES(Z_EXPECTED_TYPE_ENUM)
1439 	Z_EXPECTED_LAST
1440 } zend_expected_type;
1441 
1442 ZEND_API ZEND_COLD void ZEND_FASTCALL zend_wrong_parameters_none_error(void);
1443 ZEND_API ZEND_COLD void ZEND_FASTCALL zend_wrong_parameters_count_error(uint32_t min_num_args, uint32_t max_num_args);
1444 ZEND_API ZEND_COLD void ZEND_FASTCALL zend_wrong_parameter_error(int error_code, uint32_t num, char *name, zend_expected_type expected_type, zval *arg);
1445 ZEND_API ZEND_COLD void ZEND_FASTCALL zend_wrong_parameter_type_error(uint32_t num, zend_expected_type expected_type, zval *arg);
1446 ZEND_API ZEND_COLD void ZEND_FASTCALL zend_wrong_parameter_class_error(uint32_t num, const char *name, zval *arg);
1447 ZEND_API ZEND_COLD void ZEND_FASTCALL zend_wrong_parameter_class_or_null_error(uint32_t num, const char *name, zval *arg);
1448 ZEND_API ZEND_COLD void ZEND_FASTCALL zend_wrong_parameter_class_or_long_error(uint32_t num, const char *name, zval *arg);
1449 ZEND_API ZEND_COLD void ZEND_FASTCALL zend_wrong_parameter_class_or_long_or_null_error(uint32_t num, const char *name, zval *arg);
1450 ZEND_API ZEND_COLD void ZEND_FASTCALL zend_wrong_parameter_class_or_string_error(uint32_t num, const char *name, zval *arg);
1451 ZEND_API ZEND_COLD void ZEND_FASTCALL zend_wrong_parameter_class_or_string_or_null_error(uint32_t num, const char *name, zval *arg);
1452 ZEND_API ZEND_COLD void ZEND_FASTCALL zend_wrong_callback_error(uint32_t num, char *error);
1453 ZEND_API ZEND_COLD void ZEND_FASTCALL zend_wrong_callback_or_null_error(uint32_t num, char *error);
1454 ZEND_API ZEND_COLD void ZEND_FASTCALL zend_unexpected_extra_named_error(void);
1455 ZEND_API ZEND_COLD void ZEND_FASTCALL zend_argument_error_variadic(zend_class_entry *error_ce, uint32_t arg_num, const char *format, va_list va);
1456 ZEND_API ZEND_COLD void zend_argument_error(zend_class_entry *error_ce, uint32_t arg_num, const char *format, ...);
1457 ZEND_API ZEND_COLD void zend_argument_type_error(uint32_t arg_num, const char *format, ...);
1458 ZEND_API ZEND_COLD void zend_argument_value_error(uint32_t arg_num, const char *format, ...);
1459 
1460 #define ZPP_ERROR_OK                            0
1461 #define ZPP_ERROR_FAILURE                       1
1462 #define ZPP_ERROR_WRONG_CALLBACK                2
1463 #define ZPP_ERROR_WRONG_CLASS                   3
1464 #define ZPP_ERROR_WRONG_CLASS_OR_NULL           4
1465 #define ZPP_ERROR_WRONG_CLASS_OR_STRING         5
1466 #define ZPP_ERROR_WRONG_CLASS_OR_STRING_OR_NULL 6
1467 #define ZPP_ERROR_WRONG_CLASS_OR_LONG           7
1468 #define ZPP_ERROR_WRONG_CLASS_OR_LONG_OR_NULL   8
1469 #define ZPP_ERROR_WRONG_ARG                     9
1470 #define ZPP_ERROR_WRONG_COUNT                   10
1471 #define ZPP_ERROR_UNEXPECTED_EXTRA_NAMED        11
1472 #define ZPP_ERROR_WRONG_CALLBACK_OR_NULL        12
1473 
1474 #define ZEND_PARSE_PARAMETERS_START_EX(flags, min_num_args, max_num_args) do { \
1475 		const int _flags = (flags); \
1476 		uint32_t _min_num_args = (min_num_args); \
1477 		uint32_t _max_num_args = (uint32_t) (max_num_args); \
1478 		uint32_t _num_args = EX_NUM_ARGS(); \
1479 		uint32_t _i = 0; \
1480 		zval *_real_arg, *_arg = NULL; \
1481 		zend_expected_type _expected_type = Z_EXPECTED_LONG; \
1482 		char *_error = NULL; \
1483 		bool _dummy = 0; \
1484 		bool _optional = 0; \
1485 		int _error_code = ZPP_ERROR_OK; \
1486 		((void)_i); \
1487 		((void)_real_arg); \
1488 		((void)_arg); \
1489 		((void)_expected_type); \
1490 		((void)_error); \
1491 		((void)_optional); \
1492 		((void)_dummy); \
1493 		\
1494 		do { \
1495 			if (UNEXPECTED(_num_args < _min_num_args) || \
1496 			    UNEXPECTED(_num_args > _max_num_args)) { \
1497 				if (!(_flags & ZEND_PARSE_PARAMS_QUIET)) { \
1498 					zend_wrong_parameters_count_error(_min_num_args, _max_num_args); \
1499 				} \
1500 				_error_code = ZPP_ERROR_FAILURE; \
1501 				break; \
1502 			} \
1503 			_real_arg = ZEND_CALL_ARG(execute_data, 0);
1504 
1505 #define ZEND_PARSE_PARAMETERS_START(min_num_args, max_num_args) \
1506 	ZEND_PARSE_PARAMETERS_START_EX(0, min_num_args, max_num_args)
1507 
1508 #define ZEND_PARSE_PARAMETERS_NONE() do { \
1509 		if (UNEXPECTED(ZEND_NUM_ARGS() != 0)) { \
1510 			zend_wrong_parameters_none_error(); \
1511 			return; \
1512 		} \
1513 	} while (0)
1514 
1515 #define ZEND_PARSE_PARAMETERS_END_EX(failure) \
1516 			ZEND_ASSERT(_i == _max_num_args || _max_num_args == (uint32_t) -1); \
1517 		} while (0); \
1518 		if (UNEXPECTED(_error_code != ZPP_ERROR_OK)) { \
1519 			if (!(_flags & ZEND_PARSE_PARAMS_QUIET)) { \
1520 				zend_wrong_parameter_error(_error_code, _i, _error, _expected_type, _arg); \
1521 			} \
1522 			failure; \
1523 		} \
1524 	} while (0)
1525 
1526 #define ZEND_PARSE_PARAMETERS_END() \
1527 	ZEND_PARSE_PARAMETERS_END_EX(return)
1528 
1529 #define Z_PARAM_PROLOGUE(deref, separate) \
1530 	++_i; \
1531 	ZEND_ASSERT(_i <= _min_num_args || _optional==1); \
1532 	ZEND_ASSERT(_i >  _min_num_args || _optional==0); \
1533 	if (_optional) { \
1534 		if (UNEXPECTED(_i >_num_args)) break; \
1535 	} \
1536 	_real_arg++; \
1537 	_arg = _real_arg; \
1538 	if (deref) { \
1539 		if (EXPECTED(Z_ISREF_P(_arg))) { \
1540 			_arg = Z_REFVAL_P(_arg); \
1541 		} \
1542 	} \
1543 	if (separate) { \
1544 		SEPARATE_ZVAL_NOREF(_arg); \
1545 	}
1546 
1547 /* get the zval* for a previously parsed argument */
1548 #define Z_PARAM_GET_PREV_ZVAL(dest) \
1549 	zend_parse_arg_zval_deref(_arg, &dest, 0);
1550 
1551 /* old "|" */
1552 #define Z_PARAM_OPTIONAL \
1553 	_optional = 1;
1554 
1555 /* old "a" */
1556 #define Z_PARAM_ARRAY_EX2(dest, check_null, deref, separate) \
1557 		Z_PARAM_PROLOGUE(deref, separate); \
1558 		if (UNEXPECTED(!zend_parse_arg_array(_arg, &dest, check_null, 0))) { \
1559 			_expected_type = check_null ? Z_EXPECTED_ARRAY_OR_NULL : Z_EXPECTED_ARRAY; \
1560 			_error_code = ZPP_ERROR_WRONG_ARG; \
1561 			break; \
1562 		}
1563 
1564 #define Z_PARAM_ARRAY_EX(dest, check_null, separate) \
1565 	Z_PARAM_ARRAY_EX2(dest, check_null, separate, separate)
1566 
1567 #define Z_PARAM_ARRAY(dest) \
1568 	Z_PARAM_ARRAY_EX(dest, 0, 0)
1569 
1570 #define Z_PARAM_ARRAY_OR_NULL(dest) \
1571 	Z_PARAM_ARRAY_EX(dest, 1, 0)
1572 
1573 /* old "A" */
1574 #define Z_PARAM_ARRAY_OR_OBJECT_EX2(dest, check_null, deref, separate) \
1575 		Z_PARAM_PROLOGUE(deref, separate); \
1576 		if (UNEXPECTED(!zend_parse_arg_array(_arg, &dest, check_null, 1))) { \
1577 			_expected_type = check_null ? Z_EXPECTED_ARRAY_OR_NULL : Z_EXPECTED_ARRAY; \
1578 			_error_code = ZPP_ERROR_WRONG_ARG; \
1579 			break; \
1580 		}
1581 
1582 #define Z_PARAM_ARRAY_OR_OBJECT_EX(dest, check_null, separate) \
1583 	Z_PARAM_ARRAY_OR_OBJECT_EX2(dest, check_null, separate, separate)
1584 
1585 #define Z_PARAM_ARRAY_OR_OBJECT(dest) \
1586 	Z_PARAM_ARRAY_OR_OBJECT_EX(dest, 0, 0)
1587 
1588 #define Z_PARAM_ITERABLE_EX(dest, check_null) \
1589 	Z_PARAM_PROLOGUE(0, 0); \
1590 	if (UNEXPECTED(!zend_parse_arg_iterable(_arg, &dest, check_null))) { \
1591 		_expected_type = check_null ? Z_EXPECTED_ITERABLE_OR_NULL : Z_EXPECTED_ITERABLE; \
1592 		_error_code = ZPP_ERROR_WRONG_ARG; \
1593 		break; \
1594 	}
1595 
1596 #define Z_PARAM_ITERABLE(dest) \
1597 	Z_PARAM_ITERABLE_EX(dest, 0)
1598 
1599 #define Z_PARAM_ITERABLE_OR_NULL(dest) \
1600 	Z_PARAM_ITERABLE_EX(dest, 1)
1601 
1602 /* old "b" */
1603 #define Z_PARAM_BOOL_EX(dest, is_null, check_null, deref) \
1604 		Z_PARAM_PROLOGUE(deref, 0); \
1605 		if (UNEXPECTED(!zend_parse_arg_bool(_arg, &dest, &is_null, check_null, _i))) { \
1606 			_expected_type = check_null ? Z_EXPECTED_BOOL_OR_NULL : Z_EXPECTED_BOOL; \
1607 			_error_code = ZPP_ERROR_WRONG_ARG; \
1608 			break; \
1609 		}
1610 
1611 #define Z_PARAM_BOOL(dest) \
1612 	Z_PARAM_BOOL_EX(dest, _dummy, 0, 0)
1613 
1614 #define Z_PARAM_BOOL_OR_NULL(dest, is_null) \
1615 	Z_PARAM_BOOL_EX(dest, is_null, 1, 0)
1616 
1617 /* old "C" */
1618 #define Z_PARAM_CLASS_EX(dest, check_null, deref) \
1619 		Z_PARAM_PROLOGUE(deref, 0); \
1620 		if (UNEXPECTED(!zend_parse_arg_class(_arg, &dest, _i, check_null))) { \
1621 			_error_code = ZPP_ERROR_FAILURE; \
1622 			break; \
1623 		}
1624 
1625 #define Z_PARAM_CLASS(dest) \
1626 	Z_PARAM_CLASS_EX(dest, 0, 0)
1627 
1628 #define Z_PARAM_CLASS_OR_NULL(dest) \
1629 	Z_PARAM_CLASS_EX(dest, 1, 0)
1630 
1631 #define Z_PARAM_OBJ_OR_CLASS_NAME_EX(dest, allow_null) \
1632 	Z_PARAM_PROLOGUE(0, 0); \
1633 	if (UNEXPECTED(!zend_parse_arg_obj_or_class_name(_arg, &dest, allow_null))) { \
1634 		_expected_type = allow_null ? Z_EXPECTED_OBJECT_OR_CLASS_NAME_OR_NULL : Z_EXPECTED_OBJECT_OR_CLASS_NAME; \
1635 		_error_code = ZPP_ERROR_WRONG_ARG; \
1636 		break; \
1637 	}
1638 
1639 #define Z_PARAM_OBJ_OR_CLASS_NAME(dest) \
1640 	Z_PARAM_OBJ_OR_CLASS_NAME_EX(dest, 0);
1641 
1642 #define Z_PARAM_OBJ_OR_CLASS_NAME_OR_NULL(dest) \
1643 	Z_PARAM_OBJ_OR_CLASS_NAME_EX(dest, 1);
1644 
1645 #define Z_PARAM_OBJ_OR_STR_EX(destination_object, destination_string, allow_null) \
1646 	Z_PARAM_PROLOGUE(0, 0); \
1647 	if (UNEXPECTED(!zend_parse_arg_obj_or_str(_arg, &destination_object, NULL, &destination_string, allow_null, _i))) { \
1648 		_expected_type = allow_null ? Z_EXPECTED_OBJECT_OR_STRING_OR_NULL : Z_EXPECTED_OBJECT_OR_STRING; \
1649 		_error_code = ZPP_ERROR_WRONG_ARG; \
1650 		break; \
1651 	}
1652 
1653 #define Z_PARAM_OBJ_OR_STR(destination_object, destination_string) \
1654 	Z_PARAM_OBJ_OR_STR_EX(destination_object, destination_string, 0);
1655 
1656 #define Z_PARAM_OBJ_OR_STR_OR_NULL(destination_object, destination_string) \
1657 	Z_PARAM_OBJ_OR_STR_EX(destination_object, destination_string, 1);
1658 
1659 #define Z_PARAM_OBJ_OF_CLASS_OR_STR_EX(destination_object, base_ce, destination_string, allow_null) \
1660 	Z_PARAM_PROLOGUE(0, 0); \
1661 	if (UNEXPECTED(!zend_parse_arg_obj_or_str(_arg, &destination_object, base_ce, &destination_string, allow_null, _i))) { \
1662 		if (base_ce) { \
1663 			_error = ZSTR_VAL((base_ce)->name); \
1664 			_error_code = allow_null ? ZPP_ERROR_WRONG_CLASS_OR_STRING_OR_NULL : ZPP_ERROR_WRONG_CLASS_OR_STRING; \
1665 			break; \
1666 		} else { \
1667 			_expected_type = allow_null ? Z_EXPECTED_OBJECT_OR_STRING_OR_NULL : Z_EXPECTED_OBJECT_OR_STRING; \
1668 			_error_code = ZPP_ERROR_WRONG_ARG; \
1669 			break; \
1670 		} \
1671 	}
1672 
1673 #define Z_PARAM_OBJ_OF_CLASS_OR_STR(destination_object, base_ce, destination_string) \
1674 	Z_PARAM_OBJ_OF_CLASS_OR_STR_EX(destination_object, base_ce, destination_string, 0);
1675 
1676 #define Z_PARAM_OBJ_OF_CLASS_OR_STR_OR_NULL(destination_object, base_ce, destination_string) \
1677 	Z_PARAM_OBJ_OF_CLASS_OR_STR_EX(destination_object, base_ce, destination_string, 1);
1678 
1679 /* old "d" */
1680 #define Z_PARAM_DOUBLE_EX(dest, is_null, check_null, deref) \
1681 		Z_PARAM_PROLOGUE(deref, 0); \
1682 		if (UNEXPECTED(!zend_parse_arg_double(_arg, &dest, &is_null, check_null, _i))) { \
1683 			_expected_type = check_null ? Z_EXPECTED_DOUBLE_OR_NULL : Z_EXPECTED_DOUBLE; \
1684 			_error_code = ZPP_ERROR_WRONG_ARG; \
1685 			break; \
1686 		}
1687 
1688 #define Z_PARAM_DOUBLE(dest) \
1689 	Z_PARAM_DOUBLE_EX(dest, _dummy, 0, 0)
1690 
1691 #define Z_PARAM_DOUBLE_OR_NULL(dest, is_null) \
1692 	Z_PARAM_DOUBLE_EX(dest, is_null, 1, 0)
1693 
1694 /* old "f" */
1695 #define Z_PARAM_FUNC_EX(dest_fci, dest_fcc, check_null, deref) \
1696 		Z_PARAM_PROLOGUE(deref, 0); \
1697 		if (UNEXPECTED(!zend_parse_arg_func(_arg, &dest_fci, &dest_fcc, check_null, &_error))) { \
1698 			if (!_error) { \
1699 				_expected_type = check_null ? Z_EXPECTED_FUNC_OR_NULL : Z_EXPECTED_FUNC; \
1700 				_error_code = ZPP_ERROR_WRONG_ARG; \
1701 			} else { \
1702 				_error_code = check_null ? ZPP_ERROR_WRONG_CALLBACK_OR_NULL : ZPP_ERROR_WRONG_CALLBACK; \
1703 			} \
1704 			break; \
1705 		} \
1706 
1707 #define Z_PARAM_FUNC(dest_fci, dest_fcc) \
1708 	Z_PARAM_FUNC_EX(dest_fci, dest_fcc, 0, 0)
1709 
1710 #define Z_PARAM_FUNC_OR_NULL(dest_fci, dest_fcc) \
1711 	Z_PARAM_FUNC_EX(dest_fci, dest_fcc, 1, 0)
1712 
1713 #define Z_PARAM_FUNC_OR_NULL_WITH_ZVAL(dest_fci, dest_fcc, dest_zp) \
1714 	Z_PARAM_FUNC_EX(dest_fci, dest_fcc, 1, 0) \
1715 	Z_PARAM_GET_PREV_ZVAL(dest_zp)
1716 
1717 /* old "h" */
1718 #define Z_PARAM_ARRAY_HT_EX2(dest, check_null, deref, separate) \
1719 		Z_PARAM_PROLOGUE(deref, separate); \
1720 		if (UNEXPECTED(!zend_parse_arg_array_ht(_arg, &dest, check_null, 0, separate))) { \
1721 			_expected_type = check_null ? Z_EXPECTED_ARRAY_OR_NULL : Z_EXPECTED_ARRAY; \
1722 			_error_code = ZPP_ERROR_WRONG_ARG; \
1723 			break; \
1724 		}
1725 
1726 #define Z_PARAM_ARRAY_HT_EX(dest, check_null, separate) \
1727 	Z_PARAM_ARRAY_HT_EX2(dest, check_null, separate, separate)
1728 
1729 #define Z_PARAM_ARRAY_HT(dest) \
1730 	Z_PARAM_ARRAY_HT_EX(dest, 0, 0)
1731 
1732 #define Z_PARAM_ARRAY_HT_OR_NULL(dest) \
1733 	Z_PARAM_ARRAY_HT_EX(dest, 1, 0)
1734 
1735 #define Z_PARAM_ARRAY_HT_OR_LONG_EX(dest_ht, dest_long, is_null, allow_null) \
1736 	Z_PARAM_PROLOGUE(0, 0); \
1737 	if (UNEXPECTED(!zend_parse_arg_array_ht_or_long(_arg, &dest_ht, &dest_long, &is_null, allow_null, _i))) { \
1738 		_expected_type = allow_null ? Z_EXPECTED_ARRAY_OR_LONG_OR_NULL : Z_EXPECTED_ARRAY_OR_LONG; \
1739 		_error_code = ZPP_ERROR_WRONG_ARG; \
1740 		break; \
1741 	}
1742 
1743 #define Z_PARAM_ARRAY_HT_OR_LONG(dest_ht, dest_long) \
1744 	Z_PARAM_ARRAY_HT_OR_LONG_EX(dest_ht, dest_long, _dummy, 0)
1745 
1746 #define Z_PARAM_ARRAY_HT_OR_LONG_OR_NULL(dest_ht, dest_long, is_null) \
1747 	Z_PARAM_ARRAY_HT_OR_LONG_EX(dest_ht, dest_long, is_null, 1)
1748 
1749 /* old "H" */
1750 #define Z_PARAM_ARRAY_OR_OBJECT_HT_EX2(dest, check_null, deref, separate) \
1751 		Z_PARAM_PROLOGUE(deref, separate); \
1752 		if (UNEXPECTED(!zend_parse_arg_array_ht(_arg, &dest, check_null, 1, separate))) { \
1753 			_expected_type = check_null ? Z_EXPECTED_ARRAY_OR_NULL : Z_EXPECTED_ARRAY; \
1754 			_error_code = ZPP_ERROR_WRONG_ARG; \
1755 			break; \
1756 		}
1757 
1758 #define Z_PARAM_ARRAY_OR_OBJECT_HT_EX(dest, check_null, separate) \
1759 	Z_PARAM_ARRAY_OR_OBJECT_HT_EX2(dest, check_null, separate, separate)
1760 
1761 #define Z_PARAM_ARRAY_OR_OBJECT_HT(dest) \
1762 	Z_PARAM_ARRAY_OR_OBJECT_HT_EX(dest, 0, 0)
1763 
1764 /* old "l" */
1765 #define Z_PARAM_LONG_EX(dest, is_null, check_null, deref) \
1766 		Z_PARAM_PROLOGUE(deref, 0); \
1767 		if (UNEXPECTED(!zend_parse_arg_long(_arg, &dest, &is_null, check_null, _i))) { \
1768 			_expected_type = check_null ? Z_EXPECTED_LONG_OR_NULL : Z_EXPECTED_LONG; \
1769 			_error_code = ZPP_ERROR_WRONG_ARG; \
1770 			break; \
1771 		}
1772 
1773 #define Z_PARAM_LONG(dest) \
1774 	Z_PARAM_LONG_EX(dest, _dummy, 0, 0)
1775 
1776 #define Z_PARAM_LONG_OR_NULL(dest, is_null) \
1777 	Z_PARAM_LONG_EX(dest, is_null, 1, 0)
1778 
1779 /* old "n" */
1780 #define Z_PARAM_NUMBER_EX(dest, check_null) \
1781 	Z_PARAM_PROLOGUE(0, 0); \
1782 	if (UNEXPECTED(!zend_parse_arg_number(_arg, &dest, check_null, _i))) { \
1783 		_expected_type = check_null ? Z_EXPECTED_NUMBER_OR_NULL : Z_EXPECTED_NUMBER; \
1784 		_error_code = ZPP_ERROR_WRONG_ARG; \
1785 		break; \
1786 	}
1787 
1788 #define Z_PARAM_NUMBER_OR_NULL(dest) \
1789 	Z_PARAM_NUMBER_EX(dest, 1)
1790 
1791 #define Z_PARAM_NUMBER(dest) \
1792 	Z_PARAM_NUMBER_EX(dest, 0)
1793 
1794 /* old "o" */
1795 #define Z_PARAM_OBJECT_EX(dest, check_null, deref) \
1796 		Z_PARAM_PROLOGUE(deref, 0); \
1797 		if (UNEXPECTED(!zend_parse_arg_object(_arg, &dest, NULL, check_null))) { \
1798 			_expected_type = check_null ? Z_EXPECTED_OBJECT_OR_NULL : Z_EXPECTED_OBJECT; \
1799 			_error_code = ZPP_ERROR_WRONG_ARG; \
1800 			break; \
1801 		}
1802 
1803 #define Z_PARAM_OBJECT(dest) \
1804 	Z_PARAM_OBJECT_EX(dest, 0, 0)
1805 
1806 #define Z_PARAM_OBJECT_OR_NULL(dest) \
1807 	Z_PARAM_OBJECT_EX(dest, 1, 0)
1808 
1809 /* The same as Z_PARAM_OBJECT_EX except that dest is a zend_object rather than a zval */
1810 #define Z_PARAM_OBJ_EX(dest, check_null, deref) \
1811 		Z_PARAM_PROLOGUE(deref, 0); \
1812 		if (UNEXPECTED(!zend_parse_arg_obj(_arg, &dest, NULL, check_null))) { \
1813 			_expected_type = check_null ? Z_EXPECTED_OBJECT_OR_NULL : Z_EXPECTED_OBJECT; \
1814 			_error_code = ZPP_ERROR_WRONG_ARG; \
1815 			break; \
1816 		}
1817 
1818 #define Z_PARAM_OBJ(dest) \
1819 	Z_PARAM_OBJ_EX(dest, 0, 0)
1820 
1821 #define Z_PARAM_OBJ_OR_NULL(dest) \
1822 	Z_PARAM_OBJ_EX(dest, 1, 0)
1823 
1824 /* old "O" */
1825 #define Z_PARAM_OBJECT_OF_CLASS_EX(dest, _ce, check_null, deref) \
1826 		Z_PARAM_PROLOGUE(deref, 0); \
1827 		if (UNEXPECTED(!zend_parse_arg_object(_arg, &dest, _ce, check_null))) { \
1828 			if (_ce) { \
1829 				_error = ZSTR_VAL((_ce)->name); \
1830 				_error_code = check_null ? ZPP_ERROR_WRONG_CLASS_OR_NULL : ZPP_ERROR_WRONG_CLASS; \
1831 				break; \
1832 			} else { \
1833 				_expected_type = check_null ? Z_EXPECTED_OBJECT_OR_NULL : Z_EXPECTED_OBJECT; \
1834 				_error_code = ZPP_ERROR_WRONG_ARG; \
1835 				break; \
1836 			} \
1837 		}
1838 
1839 #define Z_PARAM_OBJECT_OF_CLASS(dest, _ce) \
1840 	Z_PARAM_OBJECT_OF_CLASS_EX(dest, _ce, 0, 0)
1841 
1842 #define Z_PARAM_OBJECT_OF_CLASS_OR_NULL(dest, _ce) \
1843 	Z_PARAM_OBJECT_OF_CLASS_EX(dest, _ce, 1, 0)
1844 
1845 /* The same as Z_PARAM_OBJECT_OF_CLASS_EX except that dest is a zend_object rather than a zval */
1846 #define Z_PARAM_OBJ_OF_CLASS_EX(dest, _ce, check_null, deref) \
1847 		Z_PARAM_PROLOGUE(deref, 0); \
1848 		if (UNEXPECTED(!zend_parse_arg_obj(_arg, &dest, _ce, check_null))) { \
1849 			if (_ce) { \
1850 				_error = ZSTR_VAL((_ce)->name); \
1851 				_error_code = check_null ? ZPP_ERROR_WRONG_CLASS_OR_NULL : ZPP_ERROR_WRONG_CLASS; \
1852 				break; \
1853 			} else { \
1854 				_expected_type = check_null ? Z_EXPECTED_OBJECT_OR_NULL : Z_EXPECTED_OBJECT; \
1855 				_error_code = ZPP_ERROR_WRONG_ARG; \
1856 				break; \
1857 			} \
1858 		}
1859 
1860 #define Z_PARAM_OBJ_OF_CLASS(dest, _ce) \
1861 	Z_PARAM_OBJ_OF_CLASS_EX(dest, _ce, 0, 0)
1862 
1863 #define Z_PARAM_OBJ_OF_CLASS_OR_NULL(dest, _ce) \
1864 	Z_PARAM_OBJ_OF_CLASS_EX(dest, _ce, 1, 0)
1865 
1866 #define Z_PARAM_OBJ_OF_CLASS_OR_LONG_EX(dest_obj, _ce, dest_long, is_null, allow_null) \
1867 		Z_PARAM_PROLOGUE(0, 0); \
1868 		if (UNEXPECTED(!zend_parse_arg_obj_or_long(_arg, &dest_obj, _ce, &dest_long, &is_null, allow_null, _i))) { \
1869 			_error = ZSTR_VAL((_ce)->name); \
1870 			_error_code = allow_null ? ZPP_ERROR_WRONG_CLASS_OR_LONG_OR_NULL : ZPP_ERROR_WRONG_CLASS_OR_LONG; \
1871 			break; \
1872 		}
1873 
1874 #define Z_PARAM_OBJ_OF_CLASS_OR_LONG(dest_obj, _ce, dest_long) \
1875 	Z_PARAM_OBJ_OF_CLASS_OR_LONG_EX(dest_obj, _ce, dest_long, _dummy, 0)
1876 
1877 #define Z_PARAM_OBJ_OF_CLASS_OR_LONG_OR_NULL(dest_obj, _ce, dest_long, is_null) \
1878 	Z_PARAM_OBJ_OF_CLASS_OR_LONG_EX(dest_obj, _ce, dest_long, is_null, 1)
1879 
1880 /* old "p" */
1881 #define Z_PARAM_PATH_EX(dest, dest_len, check_null, deref) \
1882 		Z_PARAM_PROLOGUE(deref, 0); \
1883 		if (UNEXPECTED(!zend_parse_arg_path(_arg, &dest, &dest_len, check_null, _i))) { \
1884 			_expected_type = check_null ? Z_EXPECTED_PATH_OR_NULL : Z_EXPECTED_PATH; \
1885 			_error_code = ZPP_ERROR_WRONG_ARG; \
1886 			break; \
1887 		}
1888 
1889 #define Z_PARAM_PATH(dest, dest_len) \
1890 	Z_PARAM_PATH_EX(dest, dest_len, 0, 0)
1891 
1892 #define Z_PARAM_PATH_OR_NULL(dest, dest_len) \
1893 	Z_PARAM_PATH_EX(dest, dest_len, 1, 0)
1894 
1895 /* old "P" */
1896 #define Z_PARAM_PATH_STR_EX(dest, check_null, deref) \
1897 		Z_PARAM_PROLOGUE(deref, 0); \
1898 		if (UNEXPECTED(!zend_parse_arg_path_str(_arg, &dest, check_null, _i))) { \
1899 			_expected_type = check_null ? Z_EXPECTED_PATH_OR_NULL : Z_EXPECTED_PATH; \
1900 			_error_code = ZPP_ERROR_WRONG_ARG; \
1901 			break; \
1902 		}
1903 
1904 #define Z_PARAM_PATH_STR(dest) \
1905 	Z_PARAM_PATH_STR_EX(dest, 0, 0)
1906 
1907 #define Z_PARAM_PATH_STR_OR_NULL(dest) \
1908 	Z_PARAM_PATH_STR_EX(dest, 1, 0)
1909 
1910 /* old "r" */
1911 #define Z_PARAM_RESOURCE_EX(dest, check_null, deref) \
1912 		Z_PARAM_PROLOGUE(deref, 0); \
1913 		if (UNEXPECTED(!zend_parse_arg_resource(_arg, &dest, check_null))) { \
1914 			_expected_type = check_null ? Z_EXPECTED_RESOURCE_OR_NULL : Z_EXPECTED_RESOURCE; \
1915 			_error_code = ZPP_ERROR_WRONG_ARG; \
1916 			break; \
1917 		}
1918 
1919 #define Z_PARAM_RESOURCE(dest) \
1920 	Z_PARAM_RESOURCE_EX(dest, 0, 0)
1921 
1922 #define Z_PARAM_RESOURCE_OR_NULL(dest) \
1923 	Z_PARAM_RESOURCE_EX(dest, 1, 0)
1924 
1925 /* old "s" */
1926 #define Z_PARAM_STRING_EX(dest, dest_len, check_null, deref) \
1927 		Z_PARAM_PROLOGUE(deref, 0); \
1928 		if (UNEXPECTED(!zend_parse_arg_string(_arg, &dest, &dest_len, check_null, _i))) { \
1929 			_expected_type = check_null ? Z_EXPECTED_STRING_OR_NULL : Z_EXPECTED_STRING; \
1930 			_error_code = ZPP_ERROR_WRONG_ARG; \
1931 			break; \
1932 		}
1933 
1934 #define Z_PARAM_STRING(dest, dest_len) \
1935 	Z_PARAM_STRING_EX(dest, dest_len, 0, 0)
1936 
1937 #define Z_PARAM_STRING_OR_NULL(dest, dest_len) \
1938 	Z_PARAM_STRING_EX(dest, dest_len, 1, 0)
1939 
1940 /* old "S" */
1941 #define Z_PARAM_STR_EX(dest, check_null, deref) \
1942 		Z_PARAM_PROLOGUE(deref, 0); \
1943 		if (UNEXPECTED(!zend_parse_arg_str(_arg, &dest, check_null, _i))) { \
1944 			_expected_type = check_null ? Z_EXPECTED_STRING_OR_NULL : Z_EXPECTED_STRING; \
1945 			_error_code = ZPP_ERROR_WRONG_ARG; \
1946 			break; \
1947 		}
1948 
1949 #define Z_PARAM_STR(dest) \
1950 	Z_PARAM_STR_EX(dest, 0, 0)
1951 
1952 #define Z_PARAM_STR_OR_NULL(dest) \
1953 	Z_PARAM_STR_EX(dest, 1, 0)
1954 
1955 /* old "z" */
1956 #define Z_PARAM_ZVAL_EX2(dest, check_null, deref, separate) \
1957 		Z_PARAM_PROLOGUE(deref, separate); \
1958 		zend_parse_arg_zval_deref(_arg, &dest, check_null);
1959 
1960 #define Z_PARAM_ZVAL_EX(dest, check_null, separate) \
1961 	Z_PARAM_ZVAL_EX2(dest, check_null, separate, separate)
1962 
1963 #define Z_PARAM_ZVAL(dest) \
1964 	Z_PARAM_ZVAL_EX(dest, 0, 0)
1965 
1966 #define Z_PARAM_ZVAL_OR_NULL(dest) \
1967 	Z_PARAM_ZVAL_EX(dest, 1, 0)
1968 
1969 /* old "+" and "*" */
1970 #define Z_PARAM_VARIADIC_EX(spec, dest, dest_num, post_varargs) do { \
1971 		uint32_t _num_varargs = _num_args - _i - (post_varargs); \
1972 		if (EXPECTED(_num_varargs > 0)) { \
1973 			dest = _real_arg + 1; \
1974 			dest_num = _num_varargs; \
1975 			_i += _num_varargs; \
1976 			_real_arg += _num_varargs; \
1977 		} else { \
1978 			dest = NULL; \
1979 			dest_num = 0; \
1980 		} \
1981 		if (UNEXPECTED(ZEND_CALL_INFO(execute_data) & ZEND_CALL_HAS_EXTRA_NAMED_PARAMS)) { \
1982 			_error_code = ZPP_ERROR_UNEXPECTED_EXTRA_NAMED; \
1983 			break; \
1984 		} \
1985 	} while (0);
1986 
1987 #define Z_PARAM_VARIADIC(spec, dest, dest_num) \
1988 	Z_PARAM_VARIADIC_EX(spec, dest, dest_num, 0)
1989 
1990 #define Z_PARAM_VARIADIC_WITH_NAMED(dest, dest_num, dest_named) do { \
1991 		uint32_t _num_varargs = _num_args - _i; \
1992 		if (EXPECTED(_num_varargs > 0)) { \
1993 			dest = _real_arg + 1; \
1994 			dest_num = _num_varargs; \
1995 		} else { \
1996 			dest = NULL; \
1997 			dest_num = 0; \
1998 		} \
1999 		if (ZEND_CALL_INFO(execute_data) & ZEND_CALL_HAS_EXTRA_NAMED_PARAMS) { \
2000 			dest_named = execute_data->extra_named_params; \
2001 		} else { \
2002 			dest_named = NULL; \
2003 		} \
2004 	} while (0);
2005 
2006 #define Z_PARAM_ARRAY_HT_OR_STR_EX(dest_ht, dest_str, allow_null) \
2007 	Z_PARAM_PROLOGUE(0, 0); \
2008 	if (UNEXPECTED(!zend_parse_arg_array_ht_or_str(_arg, &dest_ht, &dest_str, allow_null, _i))) { \
2009 		_expected_type = allow_null ? Z_EXPECTED_ARRAY_OR_STRING_OR_NULL : Z_EXPECTED_ARRAY_OR_STRING; \
2010 		_error_code = ZPP_ERROR_WRONG_ARG; \
2011 		break; \
2012 	}
2013 
2014 #define Z_PARAM_ARRAY_HT_OR_STR(dest_ht, dest_str) \
2015 	Z_PARAM_ARRAY_HT_OR_STR_EX(dest_ht, dest_str, 0);
2016 
2017 #define Z_PARAM_ARRAY_HT_OR_STR_OR_NULL(dest_ht, dest_str) \
2018 	Z_PARAM_ARRAY_HT_OR_STR_EX(dest_ht, dest_str, 1);
2019 
2020 #define Z_PARAM_STR_OR_LONG_EX(dest_str, dest_long, is_null, allow_null) \
2021 	Z_PARAM_PROLOGUE(0, 0); \
2022 	if (UNEXPECTED(!zend_parse_arg_str_or_long(_arg, &dest_str, &dest_long, &is_null, allow_null, _i))) { \
2023 		_expected_type = allow_null ? Z_EXPECTED_STRING_OR_LONG_OR_NULL : Z_EXPECTED_STRING_OR_LONG; \
2024 		_error_code = ZPP_ERROR_WRONG_ARG; \
2025 		break; \
2026 	}
2027 
2028 #define Z_PARAM_STR_OR_LONG(dest_str, dest_long) \
2029 	Z_PARAM_STR_OR_LONG_EX(dest_str, dest_long, _dummy, 0);
2030 
2031 #define Z_PARAM_STR_OR_LONG_OR_NULL(dest_str, dest_long, is_null) \
2032 	Z_PARAM_STR_OR_LONG_EX(dest_str, dest_long, is_null, 1);
2033 
2034 /* End of new parameter parsing API */
2035 
2036 /* Inlined implementations shared by new and old parameter parsing APIs */
2037 
2038 ZEND_API bool ZEND_FASTCALL zend_parse_arg_class(zval *arg, zend_class_entry **pce, uint32_t num, bool check_null);
2039 ZEND_API bool ZEND_FASTCALL zend_parse_arg_bool_slow(zval *arg, bool *dest, uint32_t arg_num);
2040 ZEND_API bool ZEND_FASTCALL zend_parse_arg_bool_weak(zval *arg, bool *dest, uint32_t arg_num);
2041 ZEND_API bool ZEND_FASTCALL zend_parse_arg_long_slow(zval *arg, zend_long *dest, uint32_t arg_num);
2042 ZEND_API bool ZEND_FASTCALL zend_parse_arg_long_weak(zval *arg, zend_long *dest, uint32_t arg_num);
2043 ZEND_API bool ZEND_FASTCALL zend_parse_arg_double_slow(zval *arg, double *dest, uint32_t arg_num);
2044 ZEND_API bool ZEND_FASTCALL zend_parse_arg_double_weak(zval *arg, double *dest, uint32_t arg_num);
2045 ZEND_API bool ZEND_FASTCALL zend_parse_arg_str_slow(zval *arg, zend_string **dest, uint32_t arg_num);
2046 ZEND_API bool ZEND_FASTCALL zend_parse_arg_str_weak(zval *arg, zend_string **dest, uint32_t arg_num);
2047 ZEND_API bool ZEND_FASTCALL zend_parse_arg_number_slow(zval *arg, zval **dest, uint32_t arg_num);
2048 ZEND_API bool ZEND_FASTCALL zend_parse_arg_str_or_long_slow(zval *arg, zend_string **dest_str, zend_long *dest_long, uint32_t arg_num);
2049 
zend_parse_arg_bool(zval * arg,bool * dest,bool * is_null,bool check_null,uint32_t arg_num)2050 static zend_always_inline bool zend_parse_arg_bool(zval *arg, bool *dest, bool *is_null, bool check_null, uint32_t arg_num)
2051 {
2052 	if (check_null) {
2053 		*is_null = 0;
2054 	}
2055 	if (EXPECTED(Z_TYPE_P(arg) == IS_TRUE)) {
2056 		*dest = 1;
2057 	} else if (EXPECTED(Z_TYPE_P(arg) == IS_FALSE)) {
2058 		*dest = 0;
2059 	} else if (check_null && Z_TYPE_P(arg) == IS_NULL) {
2060 		*is_null = 1;
2061 		*dest = 0;
2062 	} else {
2063 		return zend_parse_arg_bool_slow(arg, dest, arg_num);
2064 	}
2065 	return 1;
2066 }
2067 
zend_parse_arg_long(zval * arg,zend_long * dest,bool * is_null,bool check_null,uint32_t arg_num)2068 static zend_always_inline bool zend_parse_arg_long(zval *arg, zend_long *dest, bool *is_null, bool check_null, uint32_t arg_num)
2069 {
2070 	if (check_null) {
2071 		*is_null = 0;
2072 	}
2073 	if (EXPECTED(Z_TYPE_P(arg) == IS_LONG)) {
2074 		*dest = Z_LVAL_P(arg);
2075 	} else if (check_null && Z_TYPE_P(arg) == IS_NULL) {
2076 		*is_null = 1;
2077 		*dest = 0;
2078 	} else {
2079 		return zend_parse_arg_long_slow(arg, dest, arg_num);
2080 	}
2081 	return 1;
2082 }
2083 
zend_parse_arg_double(zval * arg,double * dest,bool * is_null,bool check_null,uint32_t arg_num)2084 static zend_always_inline bool zend_parse_arg_double(zval *arg, double *dest, bool *is_null, bool check_null, uint32_t arg_num)
2085 {
2086 	if (check_null) {
2087 		*is_null = 0;
2088 	}
2089 	if (EXPECTED(Z_TYPE_P(arg) == IS_DOUBLE)) {
2090 		*dest = Z_DVAL_P(arg);
2091 	} else if (check_null && Z_TYPE_P(arg) == IS_NULL) {
2092 		*is_null = 1;
2093 		*dest = 0.0;
2094 	} else {
2095 		return zend_parse_arg_double_slow(arg, dest, arg_num);
2096 	}
2097 	return 1;
2098 }
2099 
zend_parse_arg_number(zval * arg,zval ** dest,bool check_null,uint32_t arg_num)2100 static zend_always_inline bool zend_parse_arg_number(zval *arg, zval **dest, bool check_null, uint32_t arg_num)
2101 {
2102 	if (EXPECTED(Z_TYPE_P(arg) == IS_LONG || Z_TYPE_P(arg) == IS_DOUBLE)) {
2103 		*dest = arg;
2104 	} else if (check_null && EXPECTED(Z_TYPE_P(arg) == IS_NULL)) {
2105 		*dest = NULL;
2106 	} else {
2107 		return zend_parse_arg_number_slow(arg, dest, arg_num);
2108 	}
2109 	return 1;
2110 }
2111 
zend_parse_arg_str(zval * arg,zend_string ** dest,bool check_null,uint32_t arg_num)2112 static zend_always_inline bool zend_parse_arg_str(zval *arg, zend_string **dest, bool check_null, uint32_t arg_num)
2113 {
2114 	if (EXPECTED(Z_TYPE_P(arg) == IS_STRING)) {
2115 		*dest = Z_STR_P(arg);
2116 	} else if (check_null && Z_TYPE_P(arg) == IS_NULL) {
2117 		*dest = NULL;
2118 	} else {
2119 		return zend_parse_arg_str_slow(arg, dest, arg_num);
2120 	}
2121 	return 1;
2122 }
2123 
zend_parse_arg_string(zval * arg,char ** dest,size_t * dest_len,bool check_null,uint32_t arg_num)2124 static zend_always_inline bool zend_parse_arg_string(zval *arg, char **dest, size_t *dest_len, bool check_null, uint32_t arg_num)
2125 {
2126 	zend_string *str;
2127 
2128 	if (!zend_parse_arg_str(arg, &str, check_null, arg_num)) {
2129 		return 0;
2130 	}
2131 	if (check_null && UNEXPECTED(!str)) {
2132 		*dest = NULL;
2133 		*dest_len = 0;
2134 	} else {
2135 		*dest = ZSTR_VAL(str);
2136 		*dest_len = ZSTR_LEN(str);
2137 	}
2138 	return 1;
2139 }
2140 
zend_parse_arg_path_str(zval * arg,zend_string ** dest,bool check_null,uint32_t arg_num)2141 static zend_always_inline bool zend_parse_arg_path_str(zval *arg, zend_string **dest, bool check_null, uint32_t arg_num)
2142 {
2143 	if (!zend_parse_arg_str(arg, dest, check_null, arg_num) ||
2144 	    (*dest && UNEXPECTED(CHECK_NULL_PATH(ZSTR_VAL(*dest), ZSTR_LEN(*dest))))) {
2145 		return 0;
2146 	}
2147 	return 1;
2148 }
2149 
zend_parse_arg_path(zval * arg,char ** dest,size_t * dest_len,bool check_null,uint32_t arg_num)2150 static zend_always_inline bool zend_parse_arg_path(zval *arg, char **dest, size_t *dest_len, bool check_null, uint32_t arg_num)
2151 {
2152 	zend_string *str;
2153 
2154 	if (!zend_parse_arg_path_str(arg, &str, check_null, arg_num)) {
2155 		return 0;
2156 	}
2157 	if (check_null && UNEXPECTED(!str)) {
2158 		*dest = NULL;
2159 		*dest_len = 0;
2160 	} else {
2161 		*dest = ZSTR_VAL(str);
2162 		*dest_len = ZSTR_LEN(str);
2163 	}
2164 	return 1;
2165 }
2166 
zend_parse_arg_iterable(zval * arg,zval ** dest,bool check_null)2167 static zend_always_inline bool zend_parse_arg_iterable(zval *arg, zval **dest, bool check_null)
2168 {
2169 	if (EXPECTED(zend_is_iterable(arg))) {
2170 		*dest = arg;
2171 		return 1;
2172 	}
2173 
2174 	if (check_null && EXPECTED(Z_TYPE_P(arg) == IS_NULL)) {
2175 		*dest = NULL;
2176 		return 1;
2177 	}
2178 
2179 	return 0;
2180 }
2181 
zend_parse_arg_array(zval * arg,zval ** dest,bool check_null,bool or_object)2182 static zend_always_inline bool zend_parse_arg_array(zval *arg, zval **dest, bool check_null, bool or_object)
2183 {
2184 	if (EXPECTED(Z_TYPE_P(arg) == IS_ARRAY) ||
2185 		(or_object && EXPECTED(Z_TYPE_P(arg) == IS_OBJECT))) {
2186 		*dest = arg;
2187 	} else if (check_null && EXPECTED(Z_TYPE_P(arg) == IS_NULL)) {
2188 		*dest = NULL;
2189 	} else {
2190 		return 0;
2191 	}
2192 	return 1;
2193 }
2194 
zend_parse_arg_array_ht(zval * arg,HashTable ** dest,bool check_null,bool or_object,bool separate)2195 static zend_always_inline bool zend_parse_arg_array_ht(zval *arg, HashTable **dest, bool check_null, bool or_object, bool separate)
2196 {
2197 	if (EXPECTED(Z_TYPE_P(arg) == IS_ARRAY)) {
2198 		*dest = Z_ARRVAL_P(arg);
2199 	} else if (or_object && EXPECTED(Z_TYPE_P(arg) == IS_OBJECT)) {
2200 		zend_object *zobj = Z_OBJ_P(arg);
2201 		if (separate
2202 		 && zobj->properties
2203 		 && UNEXPECTED(GC_REFCOUNT(zobj->properties) > 1)) {
2204 			if (EXPECTED(!(GC_FLAGS(zobj->properties) & IS_ARRAY_IMMUTABLE))) {
2205 				GC_DELREF(zobj->properties);
2206 			}
2207 			zobj->properties = zend_array_dup(zobj->properties);
2208 		}
2209 		*dest = zobj->handlers->get_properties(zobj);
2210 	} else if (check_null && EXPECTED(Z_TYPE_P(arg) == IS_NULL)) {
2211 		*dest = NULL;
2212 	} else {
2213 		return 0;
2214 	}
2215 	return 1;
2216 }
2217 
zend_parse_arg_array_ht_or_long(zval * arg,HashTable ** dest_ht,zend_long * dest_long,bool * is_null,bool allow_null,uint32_t arg_num)2218 static zend_always_inline bool zend_parse_arg_array_ht_or_long(
2219 	zval *arg, HashTable **dest_ht, zend_long *dest_long, bool *is_null, bool allow_null, uint32_t arg_num
2220 ) {
2221 	if (allow_null) {
2222 		*is_null = 0;
2223 	}
2224 
2225 	if (EXPECTED(Z_TYPE_P(arg) == IS_ARRAY)) {
2226 		*dest_ht = Z_ARRVAL_P(arg);
2227 	} else if (EXPECTED(Z_TYPE_P(arg) == IS_LONG)) {
2228 		*dest_ht = NULL;
2229 		*dest_long = Z_LVAL_P(arg);
2230 	} else if (allow_null && EXPECTED(Z_TYPE_P(arg) == IS_NULL)) {
2231 		*dest_ht = NULL;
2232 		*is_null = 1;
2233 	} else {
2234 		*dest_ht = NULL;
2235 		return zend_parse_arg_long_slow(arg, dest_long, arg_num);
2236 	}
2237 
2238 	return 1;
2239 }
2240 
zend_parse_arg_object(zval * arg,zval ** dest,zend_class_entry * ce,bool check_null)2241 static zend_always_inline bool zend_parse_arg_object(zval *arg, zval **dest, zend_class_entry *ce, bool check_null)
2242 {
2243 	if (EXPECTED(Z_TYPE_P(arg) == IS_OBJECT) &&
2244 	    (!ce || EXPECTED(instanceof_function(Z_OBJCE_P(arg), ce) != 0))) {
2245 		*dest = arg;
2246 	} else if (check_null && EXPECTED(Z_TYPE_P(arg) == IS_NULL)) {
2247 		*dest = NULL;
2248 	} else {
2249 		return 0;
2250 	}
2251 	return 1;
2252 }
2253 
zend_parse_arg_obj(zval * arg,zend_object ** dest,zend_class_entry * ce,bool check_null)2254 static zend_always_inline bool zend_parse_arg_obj(zval *arg, zend_object **dest, zend_class_entry *ce, bool check_null)
2255 {
2256 	if (EXPECTED(Z_TYPE_P(arg) == IS_OBJECT) &&
2257 	    (!ce || EXPECTED(instanceof_function(Z_OBJCE_P(arg), ce) != 0))) {
2258 		*dest = Z_OBJ_P(arg);
2259 	} else if (check_null && EXPECTED(Z_TYPE_P(arg) == IS_NULL)) {
2260 		*dest = NULL;
2261 	} else {
2262 		return 0;
2263 	}
2264 	return 1;
2265 }
2266 
zend_parse_arg_obj_or_long(zval * arg,zend_object ** dest_obj,zend_class_entry * ce,zend_long * dest_long,bool * is_null,bool allow_null,uint32_t arg_num)2267 static zend_always_inline bool zend_parse_arg_obj_or_long(
2268 	zval *arg, zend_object **dest_obj, zend_class_entry *ce, zend_long *dest_long, bool *is_null, bool allow_null, uint32_t arg_num
2269 ) {
2270 	if (allow_null) {
2271 		*is_null = 0;
2272 	}
2273 
2274 	if (EXPECTED(Z_TYPE_P(arg) == IS_OBJECT) && EXPECTED(instanceof_function(Z_OBJCE_P(arg), ce) != 0)) {
2275 		*dest_obj = Z_OBJ_P(arg);
2276 	} else if (EXPECTED(Z_TYPE_P(arg) == IS_LONG)) {
2277 		*dest_obj = NULL;
2278 		*dest_long = Z_LVAL_P(arg);
2279 	} else if (allow_null && EXPECTED(Z_TYPE_P(arg) == IS_NULL)) {
2280 		*dest_obj = NULL;
2281 		*is_null = 1;
2282 	} else {
2283 		*dest_obj = NULL;
2284 		return zend_parse_arg_long_slow(arg, dest_long, arg_num);
2285 	}
2286 
2287 	return 1;
2288 }
2289 
zend_parse_arg_resource(zval * arg,zval ** dest,bool check_null)2290 static zend_always_inline bool zend_parse_arg_resource(zval *arg, zval **dest, bool check_null)
2291 {
2292 	if (EXPECTED(Z_TYPE_P(arg) == IS_RESOURCE)) {
2293 		*dest = arg;
2294 	} else if (check_null && EXPECTED(Z_TYPE_P(arg) == IS_NULL)) {
2295 		*dest = NULL;
2296 	} else {
2297 		return 0;
2298 	}
2299 	return 1;
2300 }
2301 
zend_parse_arg_func(zval * arg,zend_fcall_info * dest_fci,zend_fcall_info_cache * dest_fcc,bool check_null,char ** error)2302 static zend_always_inline bool zend_parse_arg_func(zval *arg, zend_fcall_info *dest_fci, zend_fcall_info_cache *dest_fcc, bool check_null, char **error)
2303 {
2304 	if (check_null && UNEXPECTED(Z_TYPE_P(arg) == IS_NULL)) {
2305 		dest_fci->size = 0;
2306 		dest_fcc->function_handler = NULL;
2307 		*error = NULL;
2308 	} else if (UNEXPECTED(zend_fcall_info_init(arg, 0, dest_fci, dest_fcc, NULL, error) != SUCCESS)) {
2309 		return 0;
2310 	}
2311 	/* Release call trampolines: The function may not get called, in which case
2312 	 * the trampoline will leak. Force it to be refetched during
2313 	 * zend_call_function instead. */
2314 	zend_release_fcall_info_cache(dest_fcc);
2315 	return 1;
2316 }
2317 
zend_parse_arg_zval(zval * arg,zval ** dest,bool check_null)2318 static zend_always_inline void zend_parse_arg_zval(zval *arg, zval **dest, bool check_null)
2319 {
2320 	*dest = (check_null &&
2321 	    (UNEXPECTED(Z_TYPE_P(arg) == IS_NULL) ||
2322 	     (UNEXPECTED(Z_ISREF_P(arg)) &&
2323 	      UNEXPECTED(Z_TYPE_P(Z_REFVAL_P(arg)) == IS_NULL)))) ? NULL : arg;
2324 }
2325 
zend_parse_arg_zval_deref(zval * arg,zval ** dest,bool check_null)2326 static zend_always_inline void zend_parse_arg_zval_deref(zval *arg, zval **dest, bool check_null)
2327 {
2328 	*dest = (check_null && UNEXPECTED(Z_TYPE_P(arg) == IS_NULL)) ? NULL : arg;
2329 }
2330 
zend_parse_arg_array_ht_or_str(zval * arg,HashTable ** dest_ht,zend_string ** dest_str,bool allow_null,uint32_t arg_num)2331 static zend_always_inline bool zend_parse_arg_array_ht_or_str(
2332 		zval *arg, HashTable **dest_ht, zend_string **dest_str, bool allow_null, uint32_t arg_num)
2333 {
2334 	if (EXPECTED(Z_TYPE_P(arg) == IS_STRING)) {
2335 		*dest_ht = NULL;
2336 		*dest_str = Z_STR_P(arg);
2337 	} else if (EXPECTED(Z_TYPE_P(arg) == IS_ARRAY)) {
2338 		*dest_ht = Z_ARRVAL_P(arg);
2339 		*dest_str = NULL;
2340 	} else if (allow_null && EXPECTED(Z_TYPE_P(arg) == IS_NULL)) {
2341 		*dest_ht = NULL;
2342 		*dest_str = NULL;
2343 	} else {
2344 		*dest_ht = NULL;
2345 		return zend_parse_arg_str_slow(arg, dest_str, arg_num);
2346 	}
2347 	return 1;
2348 }
2349 
zend_parse_arg_str_or_long(zval * arg,zend_string ** dest_str,zend_long * dest_long,bool * is_null,bool allow_null,uint32_t arg_num)2350 static zend_always_inline bool zend_parse_arg_str_or_long(zval *arg, zend_string **dest_str, zend_long *dest_long,
2351 	bool *is_null, bool allow_null, uint32_t arg_num)
2352 {
2353 	if (allow_null) {
2354 		*is_null = 0;
2355 	}
2356 	if (EXPECTED(Z_TYPE_P(arg) == IS_STRING)) {
2357 		*dest_str = Z_STR_P(arg);
2358 	} else if (EXPECTED(Z_TYPE_P(arg) == IS_LONG)) {
2359 		*dest_str = NULL;
2360 		*dest_long = Z_LVAL_P(arg);
2361 	} else if (allow_null && EXPECTED(Z_TYPE_P(arg) == IS_NULL)) {
2362 		*dest_str = NULL;
2363 		*is_null = 1;
2364 	} else {
2365 		return zend_parse_arg_str_or_long_slow(arg, dest_str, dest_long, arg_num);
2366 	}
2367 	return 1;
2368 }
2369 
zend_parse_arg_obj_or_class_name(zval * arg,zend_class_entry ** destination,bool allow_null)2370 static zend_always_inline bool zend_parse_arg_obj_or_class_name(
2371 	zval *arg, zend_class_entry **destination, bool allow_null
2372 ) {
2373 	if (EXPECTED(Z_TYPE_P(arg) == IS_STRING)) {
2374 		*destination = zend_lookup_class(Z_STR_P(arg));
2375 
2376 		return *destination != NULL;
2377 	} else if (EXPECTED(Z_TYPE_P(arg) == IS_OBJECT)) {
2378 		*destination = Z_OBJ_P(arg)->ce;
2379 	} else if (allow_null && EXPECTED(Z_TYPE_P(arg) == IS_NULL)) {
2380 		*destination = NULL;
2381 	} else {
2382 		return 0;
2383 	}
2384 
2385 	return 1;
2386 }
2387 
zend_parse_arg_obj_or_str(zval * arg,zend_object ** destination_object,zend_class_entry * base_ce,zend_string ** destination_string,bool allow_null,uint32_t arg_num)2388 static zend_always_inline bool zend_parse_arg_obj_or_str(
2389 	zval *arg, zend_object **destination_object, zend_class_entry *base_ce, zend_string **destination_string, bool allow_null, uint32_t arg_num
2390 ) {
2391 	if (EXPECTED(Z_TYPE_P(arg) == IS_OBJECT)) {
2392 		if (!base_ce || EXPECTED(instanceof_function(Z_OBJCE_P(arg), base_ce))) {
2393 			*destination_object = Z_OBJ_P(arg);
2394 			*destination_string = NULL;
2395 			return 1;
2396 		}
2397 	}
2398 
2399 	*destination_object = NULL;
2400 	return zend_parse_arg_str(arg, destination_string, allow_null, arg_num);
2401 }
2402 
2403 END_EXTERN_C()
2404 
2405 #endif /* ZEND_API_H */
2406