1/*
2   +----------------------------------------------------------------------+
3   | Zend Engine                                                          |
4   +----------------------------------------------------------------------+
5   | Copyright (c) 1998-2014 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@zend.com>                                |
16   |          Zeev Suraski <zeev@zend.com>                                |
17   |          Andrei Zmievski <andrei@php.net>                            |
18   +----------------------------------------------------------------------+
19*/
20
21/* $Id$ */
22
23#ifndef ZEND_API_H
24#define ZEND_API_H
25
26#include "zend_modules.h"
27#include "zend_list.h"
28#include "zend_operators.h"
29#include "zend_variables.h"
30#include "zend_execute.h"
31
32
33BEGIN_EXTERN_C()
34
35typedef struct _zend_function_entry {
36    const char *fname;
37    void (*handler)(INTERNAL_FUNCTION_PARAMETERS);
38    const struct _zend_arg_info *arg_info;
39    uint32_t num_args;
40    uint32_t flags;
41} zend_function_entry;
42
43typedef struct _zend_fcall_info {
44    size_t size;
45    HashTable *function_table;
46    zval function_name;
47    zend_array *symbol_table;
48    zval *retval;
49    zval *params;
50    zend_object *object;
51    zend_bool no_separation;
52    uint32_t param_count;
53} zend_fcall_info;
54
55typedef struct _zend_fcall_info_cache {
56    zend_bool initialized;
57    zend_function *function_handler;
58    zend_class_entry *calling_scope;
59    zend_class_entry *called_scope;
60    zend_object *object;
61} zend_fcall_info_cache;
62
63#define ZEND_NS_NAME(ns, name)          ns "\\" name
64
65#define ZEND_FN(name) zif_##name
66#define ZEND_MN(name) zim_##name
67#define ZEND_NAMED_FUNCTION(name)       void name(INTERNAL_FUNCTION_PARAMETERS)
68#define ZEND_FUNCTION(name)             ZEND_NAMED_FUNCTION(ZEND_FN(name))
69#define ZEND_METHOD(classname, name)    ZEND_NAMED_FUNCTION(ZEND_MN(classname##_##name))
70
71#define ZEND_FENTRY(zend_name, name, arg_info, flags)   { #zend_name, name, arg_info, (uint32_t) (sizeof(arg_info)/sizeof(struct _zend_arg_info)-1), flags },
72
73#define ZEND_RAW_FENTRY(zend_name, name, arg_info, flags)   { zend_name, name, arg_info, (uint32_t) (sizeof(arg_info)/sizeof(struct _zend_arg_info)-1), flags },
74#define ZEND_RAW_NAMED_FE(zend_name, name, arg_info) ZEND_RAW_FENTRY(#zend_name, name, arg_info, 0)
75
76#define ZEND_NAMED_FE(zend_name, name, arg_info)    ZEND_FENTRY(zend_name, name, arg_info, 0)
77#define ZEND_FE(name, arg_info)                     ZEND_FENTRY(name, ZEND_FN(name), arg_info, 0)
78#define ZEND_DEP_FE(name, arg_info)                 ZEND_FENTRY(name, ZEND_FN(name), arg_info, ZEND_ACC_DEPRECATED)
79#define ZEND_FALIAS(name, alias, arg_info)          ZEND_FENTRY(name, ZEND_FN(alias), arg_info, 0)
80#define ZEND_DEP_FALIAS(name, alias, arg_info)      ZEND_FENTRY(name, ZEND_FN(alias), arg_info, ZEND_ACC_DEPRECATED)
81#define ZEND_NAMED_ME(zend_name, name, arg_info, flags) ZEND_FENTRY(zend_name, name, arg_info, flags)
82#define ZEND_ME(classname, name, arg_info, flags)   ZEND_FENTRY(name, ZEND_MN(classname##_##name), arg_info, flags)
83#define ZEND_ABSTRACT_ME(classname, name, arg_info) ZEND_FENTRY(name, NULL, arg_info, ZEND_ACC_PUBLIC|ZEND_ACC_ABSTRACT)
84#define ZEND_MALIAS(classname, name, alias, arg_info, flags) \
85                                                    ZEND_FENTRY(name, ZEND_MN(classname##_##alias), arg_info, flags)
86#define ZEND_ME_MAPPING(name, func_name, arg_types, flags) ZEND_NAMED_ME(name, ZEND_FN(func_name), arg_types, flags)
87
88#define ZEND_NS_FENTRY(ns, zend_name, name, arg_info, flags)        ZEND_RAW_FENTRY(ZEND_NS_NAME(ns, #zend_name), name, arg_info, flags)
89
90#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)
91#define ZEND_NS_RAW_NAMED_FE(ns, zend_name, name, arg_info)         ZEND_NS_RAW_FENTRY(ns, #zend_name, name, arg_info, 0)
92
93#define ZEND_NS_NAMED_FE(ns, zend_name, name, arg_info) ZEND_NS_FENTRY(ns, zend_name, name, arg_info, 0)
94#define ZEND_NS_FE(ns, name, arg_info)                  ZEND_NS_FENTRY(ns, name, ZEND_FN(name), arg_info, 0)
95#define ZEND_NS_DEP_FE(ns, name, arg_info)              ZEND_NS_FENTRY(ns, name, ZEND_FN(name), arg_info, ZEND_ACC_DEPRECATED)
96#define ZEND_NS_FALIAS(ns, name, alias, arg_info)       ZEND_NS_FENTRY(ns, name, ZEND_FN(alias), arg_info, 0)
97#define ZEND_NS_DEP_FALIAS(ns, name, alias, arg_info)   ZEND_NS_FENTRY(ns, name, ZEND_FN(alias), arg_info, ZEND_ACC_DEPRECATED)
98
99#define ZEND_FE_END            { NULL, NULL, NULL, 0, 0 }
100
101#define ZEND_ARG_INFO(pass_by_ref, name)                            { #name, sizeof(#name)-1, NULL, 0, 0, pass_by_ref, 0, 0 },
102#define ZEND_ARG_PASS_INFO(pass_by_ref)                             { NULL, 0, NULL, 0, 0, pass_by_ref, 0, 0 },
103#define ZEND_ARG_OBJ_INFO(pass_by_ref, name, classname, allow_null) { #name, sizeof(#name)-1, #classname, sizeof(#classname)-1, IS_OBJECT, pass_by_ref, allow_null, 0 },
104#define ZEND_ARG_ARRAY_INFO(pass_by_ref, name, allow_null) { #name, sizeof(#name)-1, NULL, 0, IS_ARRAY, pass_by_ref, allow_null, 0 },
105#define ZEND_ARG_TYPE_INFO(pass_by_ref, name, type_hint, allow_null) { #name, sizeof(#name)-1, NULL, 0, type_hint, pass_by_ref, allow_null, 0 },
106#define ZEND_ARG_VARIADIC_INFO(pass_by_ref, name)                   { #name, sizeof(#name)-1, NULL, 0, 0, pass_by_ref, 0, 1 },
107
108#define ZEND_BEGIN_ARG_INFO_EX(name, _unused, return_reference, required_num_args)  \
109    static const zend_arg_info name[] = {                                                                       \
110        { NULL, 0, NULL, required_num_args, 0, return_reference, 0, 0 },
111#define ZEND_BEGIN_ARG_INFO(name, _unused)  \
112    ZEND_BEGIN_ARG_INFO_EX(name, 0, ZEND_RETURN_VALUE, -1)
113#define ZEND_END_ARG_INFO()     };
114
115/* Name macros */
116#define ZEND_MODULE_STARTUP_N(module)       zm_startup_##module
117#define ZEND_MODULE_SHUTDOWN_N(module)      zm_shutdown_##module
118#define ZEND_MODULE_ACTIVATE_N(module)      zm_activate_##module
119#define ZEND_MODULE_DEACTIVATE_N(module)    zm_deactivate_##module
120#define ZEND_MODULE_POST_ZEND_DEACTIVATE_N(module)  zm_post_zend_deactivate_##module
121#define ZEND_MODULE_INFO_N(module)          zm_info_##module
122#define ZEND_MODULE_GLOBALS_CTOR_N(module)  zm_globals_ctor_##module
123#define ZEND_MODULE_GLOBALS_DTOR_N(module)  zm_globals_dtor_##module
124
125/* Declaration macros */
126#define ZEND_MODULE_STARTUP_D(module)       int ZEND_MODULE_STARTUP_N(module)(INIT_FUNC_ARGS)
127#define ZEND_MODULE_SHUTDOWN_D(module)      int ZEND_MODULE_SHUTDOWN_N(module)(SHUTDOWN_FUNC_ARGS)
128#define ZEND_MODULE_ACTIVATE_D(module)      int ZEND_MODULE_ACTIVATE_N(module)(INIT_FUNC_ARGS)
129#define ZEND_MODULE_DEACTIVATE_D(module)    int ZEND_MODULE_DEACTIVATE_N(module)(SHUTDOWN_FUNC_ARGS)
130#define ZEND_MODULE_POST_ZEND_DEACTIVATE_D(module)  int ZEND_MODULE_POST_ZEND_DEACTIVATE_N(module)(void)
131#define ZEND_MODULE_INFO_D(module)          void ZEND_MODULE_INFO_N(module)(ZEND_MODULE_INFO_FUNC_ARGS)
132#define ZEND_MODULE_GLOBALS_CTOR_D(module)  void ZEND_MODULE_GLOBALS_CTOR_N(module)(zend_##module##_globals *module##_globals TSRMLS_DC)
133#define ZEND_MODULE_GLOBALS_DTOR_D(module)  void ZEND_MODULE_GLOBALS_DTOR_N(module)(zend_##module##_globals *module##_globals TSRMLS_DC)
134
135#define ZEND_GET_MODULE(name) \
136    BEGIN_EXTERN_C()\
137    ZEND_DLEXPORT zend_module_entry *get_module(void) { return &name##_module_entry; }\
138    END_EXTERN_C()
139
140#define ZEND_BEGIN_MODULE_GLOBALS(module_name)      \
141    typedef struct _zend_##module_name##_globals {
142#define ZEND_END_MODULE_GLOBALS(module_name)        \
143    } zend_##module_name##_globals;
144
145#ifdef ZTS
146
147#define ZEND_DECLARE_MODULE_GLOBALS(module_name)                            \
148    ts_rsrc_id module_name##_globals_id;
149#define ZEND_EXTERN_MODULE_GLOBALS(module_name)                             \
150    extern ts_rsrc_id module_name##_globals_id;
151#define ZEND_INIT_MODULE_GLOBALS(module_name, globals_ctor, globals_dtor)   \
152    ts_allocate_id(&module_name##_globals_id, sizeof(zend_##module_name##_globals), (ts_allocate_ctor) globals_ctor, (ts_allocate_dtor) globals_dtor);
153
154#else
155
156#define ZEND_DECLARE_MODULE_GLOBALS(module_name)                            \
157    zend_##module_name##_globals module_name##_globals;
158#define ZEND_EXTERN_MODULE_GLOBALS(module_name)                             \
159    extern zend_##module_name##_globals module_name##_globals;
160#define ZEND_INIT_MODULE_GLOBALS(module_name, globals_ctor, globals_dtor)   \
161    globals_ctor(&module_name##_globals);
162
163#endif
164
165#define INIT_CLASS_ENTRY(class_container, class_name, functions) \
166    INIT_OVERLOADED_CLASS_ENTRY(class_container, class_name, functions, NULL, NULL, NULL)
167
168#define INIT_CLASS_ENTRY_EX(class_container, class_name, class_name_len, functions) \
169    INIT_OVERLOADED_CLASS_ENTRY_EX(class_container, class_name, class_name_len, functions, NULL, NULL, NULL, NULL, NULL)
170
171#define INIT_OVERLOADED_CLASS_ENTRY_EX(class_container, class_name, class_name_len, functions, handle_fcall, handle_propget, handle_propset, handle_propunset, handle_propisset) \
172    {                                                           \
173        zend_string *cl_name;                                   \
174        cl_name = zend_string_init(class_name, class_name_len, 1);      \
175        class_container.name = zend_new_interned_string(cl_name TSRMLS_CC); \
176        INIT_CLASS_ENTRY_INIT_METHODS(class_container, functions, handle_fcall, handle_propget, handle_propset, handle_propunset, handle_propisset) \
177    }
178
179#define INIT_CLASS_ENTRY_INIT_METHODS(class_container, functions, handle_fcall, handle_propget, handle_propset, handle_propunset, handle_propisset) \
180    {                                                           \
181        class_container.constructor = NULL;                     \
182        class_container.destructor = NULL;                      \
183        class_container.clone = NULL;                           \
184        class_container.serialize = NULL;                       \
185        class_container.unserialize = NULL;                     \
186        class_container.create_object = NULL;                   \
187        class_container.interface_gets_implemented = NULL;      \
188        class_container.get_static_method = NULL;               \
189        class_container.__call = handle_fcall;                  \
190        class_container.__callstatic = NULL;                    \
191        class_container.__tostring = NULL;                      \
192        class_container.__get = handle_propget;                 \
193        class_container.__set = handle_propset;                 \
194        class_container.__unset = handle_propunset;             \
195        class_container.__isset = handle_propisset;             \
196        class_container.__debugInfo = NULL;                 \
197        class_container.serialize_func = NULL;                  \
198        class_container.unserialize_func = NULL;                \
199        class_container.serialize = NULL;                       \
200        class_container.unserialize = NULL;                     \
201        class_container.parent = NULL;                          \
202        class_container.num_interfaces = 0;                     \
203        class_container.traits = NULL;                          \
204        class_container.num_traits = 0;                         \
205        class_container.trait_aliases = NULL;                   \
206        class_container.trait_precedences = NULL;               \
207        class_container.interfaces = NULL;                      \
208        class_container.get_iterator = NULL;                    \
209        class_container.iterator_funcs.funcs = NULL;            \
210        class_container.info.internal.module = NULL;            \
211        class_container.info.internal.builtin_functions = functions;    \
212    }
213
214#define INIT_OVERLOADED_CLASS_ENTRY(class_container, class_name, functions, handle_fcall, handle_propget, handle_propset) \
215    INIT_OVERLOADED_CLASS_ENTRY_EX(class_container, class_name, sizeof(class_name)-1, functions, handle_fcall, handle_propget, handle_propset, NULL, NULL)
216
217#define INIT_NS_CLASS_ENTRY(class_container, ns, class_name, functions) \
218    INIT_CLASS_ENTRY(class_container, ZEND_NS_NAME(ns, class_name), functions)
219#define INIT_OVERLOADED_NS_CLASS_ENTRY_EX(class_container, ns, class_name, functions, handle_fcall, handle_propget, handle_propset, handle_propunset, handle_propisset) \
220    INIT_OVERLOADED_CLASS_ENTRY_EX(class_container, ZEND_NS_NAME(ns, class_name), sizeof(ZEND_NS_NAME(ns, class_name))-1, functions, handle_fcall, handle_propget, handle_propset, handle_propunset, handle_propisset)
221#define INIT_OVERLOADED_NS_CLASS_ENTRY(class_container, ns, class_name, functions, handle_fcall, handle_propget, handle_propset) \
222    INIT_OVERLOADED_CLASS_ENTRY(class_container, ZEND_NS_NAME(ns, class_name), functions, handle_fcall, handle_propget, handle_propset)
223
224#ifdef ZTS
225#   define CE_STATIC_MEMBERS(ce) (((ce)->type==ZEND_USER_CLASS)?(ce)->static_members_table:CG(static_members_table)[(zend_intptr_t)(ce)->static_members_table])
226#else
227#   define CE_STATIC_MEMBERS(ce) ((ce)->static_members_table)
228#endif
229
230#define ZEND_FCI_INITIALIZED(fci) ((fci).size != 0)
231
232ZEND_API int zend_next_free_module(void);
233
234BEGIN_EXTERN_C()
235ZEND_API int zend_get_parameters(int ht, int param_count, ...);
236ZEND_API ZEND_ATTRIBUTE_DEPRECATED int zend_get_parameters_ex(int param_count, ...);
237ZEND_API int _zend_get_parameters_array_ex(int param_count, zval *argument_array TSRMLS_DC);
238
239/* internal function to efficiently copy parameters when executing __call() */
240ZEND_API int zend_copy_parameters_array(int param_count, zval *argument_array TSRMLS_DC);
241
242#define zend_get_parameters_array(ht, param_count, argument_array)          \
243    _zend_get_parameters_array_ex(param_count, argument_array TSRMLS_CC)
244#define zend_get_parameters_array_ex(param_count, argument_array)           \
245    _zend_get_parameters_array_ex(param_count, argument_array TSRMLS_CC)
246#define zend_parse_parameters_none()                                        \
247    zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "")
248
249/* Parameter parsing API -- andrei */
250
251#define ZEND_PARSE_PARAMS_QUIET (1<<1)
252ZEND_API int zend_parse_parameters(int num_args TSRMLS_DC, const char *type_spec, ...);
253ZEND_API int zend_parse_parameters_ex(int flags, int num_args TSRMLS_DC, const char *type_spec, ...);
254ZEND_API char *zend_zval_type_name(const zval *arg);
255
256ZEND_API int zend_parse_method_parameters(int num_args TSRMLS_DC, zval *this_ptr, const char *type_spec, ...);
257ZEND_API int zend_parse_method_parameters_ex(int flags, int num_args TSRMLS_DC, zval *this_ptr, const char *type_spec, ...);
258
259ZEND_API int zend_parse_parameter(int flags, int arg_num TSRMLS_DC, zval *arg, const char *spec, ...);
260
261/* End of parameter parsing API -- andrei */
262
263ZEND_API int zend_register_functions(zend_class_entry *scope, const zend_function_entry *functions, HashTable *function_table, int type TSRMLS_DC);
264ZEND_API void zend_unregister_functions(const zend_function_entry *functions, int count, HashTable *function_table TSRMLS_DC);
265ZEND_API int zend_startup_module(zend_module_entry *module_entry TSRMLS_DC);
266ZEND_API zend_module_entry* zend_register_internal_module(zend_module_entry *module_entry TSRMLS_DC);
267ZEND_API zend_module_entry* zend_register_module_ex(zend_module_entry *module TSRMLS_DC);
268ZEND_API int zend_startup_module_ex(zend_module_entry *module TSRMLS_DC);
269ZEND_API int zend_startup_modules(TSRMLS_D);
270ZEND_API void zend_collect_module_handlers(TSRMLS_D);
271ZEND_API void zend_destroy_modules(void);
272ZEND_API void zend_check_magic_method_implementation(const zend_class_entry *ce, const zend_function *fptr, int error_type TSRMLS_DC);
273
274ZEND_API zend_class_entry *zend_register_internal_class(zend_class_entry *class_entry TSRMLS_DC);
275ZEND_API zend_class_entry *zend_register_internal_class_ex(zend_class_entry *class_entry, zend_class_entry *parent_ce TSRMLS_DC);
276ZEND_API zend_class_entry *zend_register_internal_interface(zend_class_entry *orig_class_entry TSRMLS_DC);
277ZEND_API void zend_class_implements(zend_class_entry *class_entry TSRMLS_DC, int num_interfaces, ...);
278
279ZEND_API int zend_register_class_alias_ex(const char *name, size_t name_len, zend_class_entry *ce TSRMLS_DC);
280
281#define zend_register_class_alias(name, ce) \
282    zend_register_class_alias_ex(name, sizeof(name)-1, ce TSRMLS_CC)
283#define zend_register_ns_class_alias(ns, name, ce) \
284    zend_register_class_alias_ex(ZEND_NS_NAME(ns, name), sizeof(ZEND_NS_NAME(ns, name))-1, ce TSRMLS_CC)
285
286ZEND_API int zend_disable_function(char *function_name, size_t function_name_length TSRMLS_DC);
287ZEND_API int zend_disable_class(char *class_name, size_t class_name_length TSRMLS_DC);
288
289ZEND_API void zend_wrong_param_count(TSRMLS_D);
290
291#define IS_CALLABLE_CHECK_SYNTAX_ONLY (1<<0)
292#define IS_CALLABLE_CHECK_NO_ACCESS   (1<<1)
293#define IS_CALLABLE_CHECK_IS_STATIC   (1<<2)
294#define IS_CALLABLE_CHECK_SILENT      (1<<3)
295
296#define IS_CALLABLE_STRICT  (IS_CALLABLE_CHECK_IS_STATIC)
297
298ZEND_API zend_bool zend_is_callable_ex(zval *callable, zend_object *object, uint check_flags, zend_string **callable_name, zend_fcall_info_cache *fcc, char **error TSRMLS_DC);
299ZEND_API zend_bool zend_is_callable(zval *callable, uint check_flags, zend_string **callable_name TSRMLS_DC);
300ZEND_API zend_bool zend_make_callable(zval *callable, zend_string **callable_name TSRMLS_DC);
301ZEND_API const char *zend_get_module_version(const char *module_name);
302ZEND_API int zend_get_module_started(const char *module_name);
303ZEND_API int zend_declare_property_ex(zend_class_entry *ce, zend_string *name, zval *property, int access_type, zend_string *doc_comment TSRMLS_DC);
304ZEND_API int zend_declare_property(zend_class_entry *ce, const char *name, size_t name_length, zval *property, int access_type TSRMLS_DC);
305ZEND_API int zend_declare_property_null(zend_class_entry *ce, const char *name, size_t name_length, int access_type TSRMLS_DC);
306ZEND_API int zend_declare_property_bool(zend_class_entry *ce, const char *name, size_t name_length, zend_long value, int access_type TSRMLS_DC);
307ZEND_API int zend_declare_property_long(zend_class_entry *ce, const char *name, size_t name_length, zend_long value, int access_type TSRMLS_DC);
308ZEND_API int zend_declare_property_double(zend_class_entry *ce, const char *name, size_t name_length, double value, int access_type TSRMLS_DC);
309ZEND_API int zend_declare_property_string(zend_class_entry *ce, const char *name, size_t name_length, const char *value, int access_type TSRMLS_DC);
310ZEND_API int 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 TSRMLS_DC);
311
312ZEND_API int zend_declare_class_constant(zend_class_entry *ce, const char *name, size_t name_length, zval *value TSRMLS_DC);
313ZEND_API int zend_declare_class_constant_null(zend_class_entry *ce, const char *name, size_t name_length TSRMLS_DC);
314ZEND_API int zend_declare_class_constant_long(zend_class_entry *ce, const char *name, size_t name_length, zend_long value TSRMLS_DC);
315ZEND_API int zend_declare_class_constant_bool(zend_class_entry *ce, const char *name, size_t name_length, zend_bool value TSRMLS_DC);
316ZEND_API int zend_declare_class_constant_double(zend_class_entry *ce, const char *name, size_t name_length, double value TSRMLS_DC);
317ZEND_API int zend_declare_class_constant_stringl(zend_class_entry *ce, const char *name, size_t name_length, const char *value, size_t value_length TSRMLS_DC);
318ZEND_API int zend_declare_class_constant_string(zend_class_entry *ce, const char *name, size_t name_length, const char *value TSRMLS_DC);
319
320ZEND_API void zend_update_class_constants(zend_class_entry *class_type TSRMLS_DC);
321ZEND_API void zend_update_property(zend_class_entry *scope, zval *object, const char *name, size_t name_length, zval *value TSRMLS_DC);
322ZEND_API void zend_update_property_null(zend_class_entry *scope, zval *object, const char *name, size_t name_length TSRMLS_DC);
323ZEND_API void zend_update_property_bool(zend_class_entry *scope, zval *object, const char *name, size_t name_length, zend_long value TSRMLS_DC);
324ZEND_API void zend_update_property_long(zend_class_entry *scope, zval *object, const char *name, size_t name_length, zend_long value TSRMLS_DC);
325ZEND_API void zend_update_property_double(zend_class_entry *scope, zval *object, const char *name, size_t name_length, double value TSRMLS_DC);
326ZEND_API void zend_update_property_str(zend_class_entry *scope, zval *object, const char *name, size_t name_length, zend_string *value TSRMLS_DC);
327ZEND_API void zend_update_property_string(zend_class_entry *scope, zval *object, const char *name, size_t name_length, const char *value TSRMLS_DC);
328ZEND_API void zend_update_property_stringl(zend_class_entry *scope, zval *object, const char *name, size_t name_length, const char *value, size_t value_length TSRMLS_DC);
329
330ZEND_API int zend_update_static_property(zend_class_entry *scope, const char *name, size_t name_length, zval *value TSRMLS_DC);
331ZEND_API int zend_update_static_property_null(zend_class_entry *scope, const char *name, size_t name_length TSRMLS_DC);
332ZEND_API int zend_update_static_property_bool(zend_class_entry *scope, const char *name, size_t name_length, zend_long value TSRMLS_DC);
333ZEND_API int zend_update_static_property_long(zend_class_entry *scope, const char *name, size_t name_length, zend_long value TSRMLS_DC);
334ZEND_API int zend_update_static_property_double(zend_class_entry *scope, const char *name, size_t name_length, double value TSRMLS_DC);
335ZEND_API int zend_update_static_property_string(zend_class_entry *scope, const char *name, size_t name_length, const char *value TSRMLS_DC);
336ZEND_API int zend_update_static_property_stringl(zend_class_entry *scope, const char *name, size_t name_length, const char *value, size_t value_length TSRMLS_DC);
337
338ZEND_API zval *zend_read_property(zend_class_entry *scope, zval *object, const char *name, size_t name_length, zend_bool silent TSRMLS_DC);
339
340ZEND_API zval *zend_read_static_property(zend_class_entry *scope, const char *name, size_t name_length, zend_bool silent TSRMLS_DC);
341
342ZEND_API char *zend_get_type_by_const(int type);
343
344#define getThis()                           (Z_OBJ(EX(This)) ? &EX(This) : NULL)
345#define ZEND_IS_METHOD_CALL()               (EX(func)->common.scope != NULL)
346
347#define WRONG_PARAM_COUNT                   ZEND_WRONG_PARAM_COUNT()
348#define WRONG_PARAM_COUNT_WITH_RETVAL(ret)  ZEND_WRONG_PARAM_COUNT_WITH_RETVAL(ret)
349#define ARG_COUNT(dummy)                    EX(num_args)
350#define ZEND_NUM_ARGS()                     EX(num_args)
351#define ZEND_WRONG_PARAM_COUNT()                    { zend_wrong_param_count(TSRMLS_C); return; }
352#define ZEND_WRONG_PARAM_COUNT_WITH_RETVAL(ret)     { zend_wrong_param_count(TSRMLS_C); return ret; }
353
354#ifndef ZEND_WIN32
355#define DLEXPORT
356#endif
357
358#define array_init(arg)         _array_init((arg), 0 ZEND_FILE_LINE_CC)
359#define array_init_size(arg, size) _array_init((arg), (size) ZEND_FILE_LINE_CC)
360#define object_init(arg)        _object_init((arg) ZEND_FILE_LINE_CC TSRMLS_CC)
361#define object_init_ex(arg, ce) _object_init_ex((arg), (ce) ZEND_FILE_LINE_CC TSRMLS_CC)
362#define object_and_properties_init(arg, ce, properties) _object_and_properties_init((arg), (ce), (properties) ZEND_FILE_LINE_CC TSRMLS_CC)
363ZEND_API int _array_init(zval *arg, uint size ZEND_FILE_LINE_DC);
364ZEND_API int _object_init(zval *arg ZEND_FILE_LINE_DC TSRMLS_DC);
365ZEND_API int _object_init_ex(zval *arg, zend_class_entry *ce ZEND_FILE_LINE_DC TSRMLS_DC);
366ZEND_API int _object_and_properties_init(zval *arg, zend_class_entry *ce, HashTable *properties ZEND_FILE_LINE_DC TSRMLS_DC);
367ZEND_API void object_properties_init(zend_object *object, zend_class_entry *class_type);
368ZEND_API void object_properties_init_ex(zend_object *object, HashTable *properties TSRMLS_DC);
369ZEND_API void object_properties_load(zend_object *object, HashTable *properties TSRMLS_DC);
370
371ZEND_API void zend_merge_properties(zval *obj, HashTable *properties TSRMLS_DC);
372
373/* no longer supported */
374ZEND_API int add_assoc_function(zval *arg, const char *key, void (*function_ptr)(INTERNAL_FUNCTION_PARAMETERS));
375
376ZEND_API int add_assoc_long_ex(zval *arg, const char *key, size_t key_len, zend_long n);
377ZEND_API int add_assoc_null_ex(zval *arg, const char *key, size_t key_len);
378ZEND_API int add_assoc_bool_ex(zval *arg, const char *key, size_t key_len, int b);
379ZEND_API int add_assoc_resource_ex(zval *arg, const char *key, size_t key_len, zend_resource *r);
380ZEND_API int add_assoc_double_ex(zval *arg, const char *key, size_t key_len, double d);
381ZEND_API int add_assoc_str_ex(zval *arg, const char *key, size_t key_len, zend_string *str);
382ZEND_API int add_assoc_string_ex(zval *arg, const char *key, size_t key_len, char *str);
383ZEND_API int add_assoc_stringl_ex(zval *arg, const char *key, size_t key_len, char *str, size_t length);
384ZEND_API int add_assoc_zval_ex(zval *arg, const char *key, size_t key_len, zval *value);
385
386#define add_assoc_long(__arg, __key, __n) add_assoc_long_ex(__arg, __key, strlen(__key), __n)
387#define add_assoc_null(__arg, __key) add_assoc_null_ex(__arg, __key, strlen(__key))
388#define add_assoc_bool(__arg, __key, __b) add_assoc_bool_ex(__arg, __key, strlen(__key), __b)
389#define add_assoc_resource(__arg, __key, __r) add_assoc_resource_ex(__arg, __key, strlen(__key), __r)
390#define add_assoc_double(__arg, __key, __d) add_assoc_double_ex(__arg, __key, strlen(__key), __d)
391#define add_assoc_str(__arg, __key, __str) add_assoc_str_ex(__arg, __key, strlen(__key), __str)
392#define add_assoc_string(__arg, __key, __str) add_assoc_string_ex(__arg, __key, strlen(__key), __str)
393#define add_assoc_stringl(__arg, __key, __str, __length) add_assoc_stringl_ex(__arg, __key, strlen(__key), __str, __length)
394#define add_assoc_zval(__arg, __key, __value) add_assoc_zval_ex(__arg, __key, strlen(__key), __value)
395
396/* unset() functions are only suported for legacy modules and null() functions should be used */
397#define add_assoc_unset(__arg, __key) add_assoc_null_ex(__arg, __key, strlen(__key))
398#define add_index_unset(__arg, __key) add_index_null(__arg, __key)
399#define add_next_index_unset(__arg) add_next_index_null(__arg)
400#define add_property_unset(__arg, __key) add_property_null(__arg, __key)
401
402ZEND_API int add_index_long(zval *arg, zend_ulong idx, zend_long n);
403ZEND_API int add_index_null(zval *arg, zend_ulong idx);
404ZEND_API int add_index_bool(zval *arg, zend_ulong idx, int b);
405ZEND_API int add_index_resource(zval *arg, zend_ulong idx, zend_resource *r);
406ZEND_API int add_index_double(zval *arg, zend_ulong idx, double d);
407ZEND_API int add_index_str(zval *arg, zend_ulong idx, zend_string *str);
408ZEND_API int add_index_string(zval *arg, zend_ulong idx, const char *str);
409ZEND_API int add_index_stringl(zval *arg, zend_ulong idx, const char *str, size_t length);
410ZEND_API int add_index_zval(zval *arg, zend_ulong index, zval *value);
411
412ZEND_API int add_next_index_long(zval *arg, zend_long n);
413ZEND_API int add_next_index_null(zval *arg);
414ZEND_API int add_next_index_bool(zval *arg, int b);
415ZEND_API int add_next_index_resource(zval *arg, zend_resource *r);
416ZEND_API int add_next_index_double(zval *arg, double d);
417ZEND_API int add_next_index_str(zval *arg, zend_string *str);
418ZEND_API int add_next_index_string(zval *arg, const char *str);
419ZEND_API int add_next_index_stringl(zval *arg, const char *str, size_t length);
420ZEND_API int add_next_index_zval(zval *arg, zval *value);
421
422ZEND_API zval *add_get_assoc_string_ex(zval *arg, const char *key, uint key_len, const char *str);
423ZEND_API zval *add_get_assoc_stringl_ex(zval *arg, const char *key, uint key_len, const char *str, size_t length);
424
425#define add_get_assoc_string(__arg, __key, __str) add_get_assoc_string_ex(__arg, __key, strlen(__key), __str)
426#define add_get_assoc_stringl(__arg, __key, __str, __length) add_get_assoc_stringl_ex(__arg, __key, strlen(__key), __str, __length)
427
428ZEND_API zval *add_get_index_long(zval *arg, zend_ulong idx, zend_long l);
429ZEND_API zval *add_get_index_double(zval *arg, zend_ulong idx, double d);
430ZEND_API zval *add_get_index_str(zval *arg, zend_ulong index, zend_string *str);
431ZEND_API zval *add_get_index_string(zval *arg, zend_ulong idx, const char *str);
432ZEND_API zval *add_get_index_stringl(zval *arg, zend_ulong idx, const char *str, size_t length);
433
434ZEND_API int array_set_zval_key(HashTable *ht, zval *key, zval *value TSRMLS_DC);
435
436ZEND_API int add_property_long_ex(zval *arg, const char *key, size_t key_len, zend_long l TSRMLS_DC);
437ZEND_API int add_property_null_ex(zval *arg, const char *key, size_t key_len TSRMLS_DC);
438ZEND_API int add_property_bool_ex(zval *arg, const char *key, size_t key_len, zend_long b TSRMLS_DC);
439ZEND_API int add_property_resource_ex(zval *arg, const char *key, size_t key_len, zend_resource *r TSRMLS_DC);
440ZEND_API int add_property_double_ex(zval *arg, const char *key, size_t key_len, double d TSRMLS_DC);
441ZEND_API int add_property_str_ex(zval *arg, const char *key, size_t key_len, zend_string *str TSRMLS_DC);
442ZEND_API int add_property_string_ex(zval *arg, const char *key, size_t key_len, const char *str TSRMLS_DC);
443ZEND_API int add_property_stringl_ex(zval *arg, const char *key, size_t key_len,  const char *str, size_t length TSRMLS_DC);
444ZEND_API int add_property_zval_ex(zval *arg, const char *key, size_t key_len, zval *value TSRMLS_DC);
445
446#define add_property_long(__arg, __key, __n) add_property_long_ex(__arg, __key, strlen(__key), __n TSRMLS_CC)
447#define add_property_null(__arg, __key) add_property_null_ex(__arg, __key, strlen(__key) TSRMLS_CC)
448#define add_property_bool(__arg, __key, __b) add_property_bool_ex(__arg, __key, strlen(__key), __b TSRMLS_CC)
449#define add_property_resource(__arg, __key, __r) add_property_resource_ex(__arg, __key, strlen(__key), __r TSRMLS_CC)
450#define add_property_double(__arg, __key, __d) add_property_double_ex(__arg, __key, strlen(__key), __d TSRMLS_CC)
451#define add_property_str(__arg, __key, __str) add_property_str_ex(__arg, __key, strlen(__key), __str TSRMLS_CC)
452#define add_property_string(__arg, __key, __str) add_property_string_ex(__arg, __key, strlen(__key), __str TSRMLS_CC)
453#define add_property_stringl(__arg, __key, __str, __length) add_property_stringl_ex(__arg, __key, strlen(__key), __str, __length TSRMLS_CC)
454#define add_property_zval(__arg, __key, __value) add_property_zval_ex(__arg, __key, strlen(__key), __value TSRMLS_CC)
455
456
457ZEND_API int call_user_function(HashTable *function_table, zval *object, zval *function_name, zval *retval_ptr, uint32_t param_count, zval params[] TSRMLS_DC);
458ZEND_API int call_user_function_ex(HashTable *function_table, zval *object, zval *function_name, zval *retval_ptr, uint32_t param_count, zval params[], int no_separation, zend_array *symbol_table TSRMLS_DC);
459
460ZEND_API extern const zend_fcall_info empty_fcall_info;
461ZEND_API extern const zend_fcall_info_cache empty_fcall_info_cache;
462
463/** Build zend_call_info/cache from a zval*
464 *
465 * Caller is responsible to provide a return value, otherwise the we will crash.
466 * fci->retval_ptr_ptr = NULL;
467 * In order to pass parameters the following members need to be set:
468 * fci->param_count = 0;
469 * fci->params = NULL;
470 * The callable_name argument may be NULL.
471 * Set check_flags to IS_CALLABLE_STRICT for every new usage!
472 */
473ZEND_API int zend_fcall_info_init(zval *callable, uint check_flags, zend_fcall_info *fci, zend_fcall_info_cache *fcc, zend_string **callable_name, char **error TSRMLS_DC);
474
475/** Clear arguments connected with zend_fcall_info *fci
476 * If free_mem is not zero then the params array gets free'd as well
477 */
478ZEND_API void zend_fcall_info_args_clear(zend_fcall_info *fci, int free_mem);
479
480/** Save current arguments from zend_fcall_info *fci
481 * params array will be set to NULL
482 */
483ZEND_API void zend_fcall_info_args_save(zend_fcall_info *fci, int *param_count, zval **params);
484
485/** Free arguments connected with zend_fcall_info *fci andset back saved ones.
486 */
487ZEND_API void zend_fcall_info_args_restore(zend_fcall_info *fci, int param_count, zval *params);
488
489/** Set or clear the arguments in the zend_call_info struct taking care of
490 * refcount. If args is NULL and arguments are set then those are cleared.
491 */
492ZEND_API int zend_fcall_info_args(zend_fcall_info *fci, zval *args TSRMLS_DC);
493ZEND_API int zend_fcall_info_args_ex(zend_fcall_info *fci, zend_function *func, zval *args TSRMLS_DC);
494
495/** Set arguments in the zend_fcall_info struct taking care of refcount.
496 * If argc is 0 the arguments which are set will be cleared, else pass
497 * a variable amount of zval** arguments.
498 */
499ZEND_API int zend_fcall_info_argp(zend_fcall_info *fci TSRMLS_DC, int argc, zval *argv);
500
501/** Set arguments in the zend_fcall_info struct taking care of refcount.
502 * If argc is 0 the arguments which are set will be cleared, else pass
503 * a variable amount of zval** arguments.
504 */
505ZEND_API int zend_fcall_info_argv(zend_fcall_info *fci TSRMLS_DC, int argc, va_list *argv);
506
507/** Set arguments in the zend_fcall_info struct taking care of refcount.
508 * If argc is 0 the arguments which are set will be cleared, else pass
509 * a variable amount of zval** arguments.
510 */
511ZEND_API int zend_fcall_info_argn(zend_fcall_info *fci TSRMLS_DC, int argc, ...);
512
513/** Call a function using information created by zend_fcall_info_init()/args().
514 * If args is given then those replace the argument info in fci is temporarily.
515 */
516ZEND_API int zend_fcall_info_call(zend_fcall_info *fci, zend_fcall_info_cache *fcc, zval *retval, zval *args TSRMLS_DC);
517
518ZEND_API int zend_call_function(zend_fcall_info *fci, zend_fcall_info_cache *fci_cache TSRMLS_DC);
519
520ZEND_API int zend_set_hash_symbol(zval *symbol, const char *name, int name_length, zend_bool is_ref, int num_symbol_tables, ...);
521
522ZEND_API int zend_delete_global_variable(zend_string *name TSRMLS_DC);
523
524ZEND_API zend_array *zend_rebuild_symbol_table(TSRMLS_D);
525ZEND_API void zend_attach_symbol_table(zend_execute_data *execute_data);
526ZEND_API void zend_detach_symbol_table(zend_execute_data *execute_data);
527ZEND_API int zend_set_local_var(zend_string *name, zval *value, int force TSRMLS_DC);
528ZEND_API int zend_set_local_var_str(const char *name, int len, zval *value, int force TSRMLS_DC);
529
530ZEND_API zend_string *zend_find_alias_name(zend_class_entry *ce, zend_string *name);
531ZEND_API zend_string *zend_resolve_method_name(zend_class_entry *ce, zend_function *f);
532
533ZEND_API void zend_ctor_make_null(zend_execute_data *execute_data);
534
535#define add_method(arg, key, method)    add_assoc_function((arg), (key), (method))
536
537ZEND_API ZEND_FUNCTION(display_disabled_function);
538ZEND_API ZEND_FUNCTION(display_disabled_class);
539END_EXTERN_C()
540
541#if ZEND_DEBUG
542#define CHECK_ZVAL_STRING(str) \
543    if ((str)->val[(str)->len] != '\0') { zend_error(E_WARNING, "String is not zero-terminated (%s)", (str)->val); }
544#define CHECK_ZVAL_STRING_REL(str) \
545    if ((str)->val[(str)->len] != '\0') { zend_error(E_WARNING, "String is not zero-terminated (%s) (source: %s:%d)", (str)->val ZEND_FILE_LINE_RELAY_CC); }
546#else
547#define CHECK_ZVAL_STRING(z)
548#define CHECK_ZVAL_STRING_REL(z)
549#endif
550
551#define CHECK_ZVAL_NULL_PATH(p) (Z_STRLEN_P(p) != strlen(Z_STRVAL_P(p)))
552#define CHECK_NULL_PATH(p, l) (strlen(p) != l)
553
554#define ZVAL_STRINGL(z, s, l) do {              \
555        ZVAL_NEW_STR(z, zend_string_init(s, l, 0));     \
556    } while (0)
557
558#define ZVAL_STRING(z, s) do {                  \
559        const char *_s = (s);                   \
560        ZVAL_STRINGL(z, _s, strlen(_s));        \
561    } while (0)
562
563#define ZVAL_EMPTY_STRING(z) do {               \
564        ZVAL_INTERNED_STR(z, STR_EMPTY_ALLOC());        \
565    } while (0)
566
567#define ZVAL_PSTRINGL(z, s, l) do {             \
568        ZVAL_NEW_STR(z, zend_string_init(s, l, 1));     \
569    } while (0)
570
571#define ZVAL_PSTRING(z, s) do {                 \
572        const char *_s = (s);                   \
573        ZVAL_PSTRINGL(z, _s, strlen(_s));       \
574    } while (0)
575
576#define ZVAL_EMPTY_PSTRING(z) do {              \
577        ZVAL_PSTRINGL(z, "", 0);                \
578    } while (0)
579
580#define ZVAL_ZVAL(z, zv, copy, dtor) do {       \
581        zval *__z = (z);                        \
582        zval *__zv = (zv);                      \
583        if (EXPECTED(!Z_ISREF_P(__zv))) {       \
584            ZVAL_COPY_VALUE(__z, __zv);         \
585        } else {                                \
586            ZVAL_COPY_VALUE(__z,                \
587                Z_REFVAL_P(__zv));              \
588        }                                       \
589        if (copy) {                             \
590            zval_opt_copy_ctor(__z);            \
591        }                                       \
592        if (dtor) {                             \
593            if (!copy) {                        \
594                ZVAL_NULL(__zv);                \
595            }                                   \
596            zval_ptr_dtor(__zv);                \
597        }                                       \
598    } while (0)
599
600#define RETVAL_BOOL(b)                  ZVAL_BOOL(return_value, b)
601#define RETVAL_NULL()                   ZVAL_NULL(return_value)
602#define RETVAL_LONG(l)                  ZVAL_LONG(return_value, l)
603#define RETVAL_DOUBLE(d)                ZVAL_DOUBLE(return_value, d)
604#define RETVAL_STR(s)                   ZVAL_STR(return_value, s)
605#define RETVAL_LONG_STR(s)              ZVAL_INTERNED_STR(return_value, s)
606#define RETVAL_NEW_STR(s)               ZVAL_NEW_STR(return_value, s)
607#define RETVAL_STRING(s)                ZVAL_STRING(return_value, s)
608#define RETVAL_STRINGL(s, l)            ZVAL_STRINGL(return_value, s, l)
609#define RETVAL_EMPTY_STRING()           ZVAL_EMPTY_STRING(return_value)
610#define RETVAL_RES(r)                   ZVAL_RES(return_value, r)
611#define RETVAL_OBJ(r)                   ZVAL_OBJ(return_value, r)
612#define RETVAL_ZVAL(zv, copy, dtor)     ZVAL_ZVAL(return_value, zv, copy, dtor)
613#define RETVAL_FALSE                    ZVAL_BOOL(return_value, 0)
614#define RETVAL_TRUE                     ZVAL_BOOL(return_value, 1)
615
616#define RETURN_BOOL(b)                  { RETVAL_BOOL(b); return; }
617#define RETURN_NULL()                   { RETVAL_NULL(); return;}
618#define RETURN_LONG(l)                  { RETVAL_LONG(l); return; }
619#define RETURN_DOUBLE(d)                { RETVAL_DOUBLE(d); return; }
620#define RETURN_STR(s)                   { RETVAL_STR(s); return; }
621#define RETURN_LONG_STR(s)              { RETVAL_LONG_STR(s); return; }
622#define RETURN_NEW_STR(s)               { RETVAL_NEW_STR(s); return; }
623#define RETURN_STRING(s)                { RETVAL_STRING(s); return; }
624#define RETURN_STRINGL(s, l)            { RETVAL_STRINGL(s, l); return; }
625#define RETURN_EMPTY_STRING()           { RETVAL_EMPTY_STRING(); return; }
626#define RETURN_RES(r)                   { RETVAL_RES(r); return; }
627#define RETURN_OBJ(r)                   { RETVAL_OBJ(r); return; }
628#define RETURN_ZVAL(zv, copy, dtor)     { RETVAL_ZVAL(zv, copy, dtor); return; }
629#define RETURN_FALSE                    { RETVAL_FALSE; return; }
630#define RETURN_TRUE                     { RETVAL_TRUE; return; }
631
632#define RETVAL_ZVAL_FAST(z) do {      \
633    zval *_z = (z);                   \
634    if (Z_ISREF_P(_z)) {              \
635        RETVAL_ZVAL(_z, 1, 0);        \
636    } else {                          \
637        zval_ptr_dtor(return_value);  \
638        ZVAL_COPY(return_value, _z);  \
639    }                                 \
640} while (0)
641
642/* May be used in internal constructors to make them return NULL */
643#define ZEND_CTOR_MAKE_NULL() \
644    zend_ctor_make_null(execute_data)
645
646#define RETURN_ZVAL_FAST(z) { RETVAL_ZVAL_FAST(z); return; }
647
648#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((p) TSRMLS_CC) : NULL)))
649#define ZVAL_IS_NULL(z) (Z_TYPE_P(z) == IS_NULL)
650
651/* For compatibility */
652#define ZEND_MINIT          ZEND_MODULE_STARTUP_N
653#define ZEND_MSHUTDOWN      ZEND_MODULE_SHUTDOWN_N
654#define ZEND_RINIT          ZEND_MODULE_ACTIVATE_N
655#define ZEND_RSHUTDOWN      ZEND_MODULE_DEACTIVATE_N
656#define ZEND_MINFO          ZEND_MODULE_INFO_N
657#define ZEND_GINIT(module)      ((void (*)(void* TSRMLS_DC))(ZEND_MODULE_GLOBALS_CTOR_N(module)))
658#define ZEND_GSHUTDOWN(module)  ((void (*)(void* TSRMLS_DC))(ZEND_MODULE_GLOBALS_DTOR_N(module)))
659
660#define ZEND_MINIT_FUNCTION         ZEND_MODULE_STARTUP_D
661#define ZEND_MSHUTDOWN_FUNCTION     ZEND_MODULE_SHUTDOWN_D
662#define ZEND_RINIT_FUNCTION         ZEND_MODULE_ACTIVATE_D
663#define ZEND_RSHUTDOWN_FUNCTION     ZEND_MODULE_DEACTIVATE_D
664#define ZEND_MINFO_FUNCTION         ZEND_MODULE_INFO_D
665#define ZEND_GINIT_FUNCTION         ZEND_MODULE_GLOBALS_CTOR_D
666#define ZEND_GSHUTDOWN_FUNCTION     ZEND_MODULE_GLOBALS_DTOR_D
667
668/* Fast parameter parsing API */
669
670/* TODO: This API is experemental. It may be changed or removed ???
671 * It should be used only for really often used functions.
672 * (Keep the original parsing code and wrap usage with #ifndef FAST_ZPP)
673 */
674#define FAST_ZPP 1
675
676#ifdef FAST_ZPP
677
678#define Z_EXPECTED_TYPES(_) \
679    _(Z_EXPECTED_LONG,      "long") \
680    _(Z_EXPECTED_BOOL,      "boolean") \
681    _(Z_EXPECTED_STRING,    "string") \
682    _(Z_EXPECTED_ARRAY,     "array") \
683    _(Z_EXPECTED_FUNC,      "valid callback") \
684    _(Z_EXPECTED_RESOURCE,  "resource") \
685    _(Z_EXPECTED_PATH,      "a valid path") \
686    _(Z_EXPECTED_OBJECT,    "object") \
687    _(Z_EXPECTED_DOUBLE,    "double")
688
689#define Z_EXPECTED_TYPE_ENUM(id, str) id,
690#define Z_EXPECTED_TYPE_STR(id, str)  str,
691
692typedef enum _zend_expected_type {
693    Z_EXPECTED_TYPES(Z_EXPECTED_TYPE_ENUM)
694    Z_EXPECTED_LAST
695} zend_expected_type;
696
697ZEND_API int parse_arg_object_to_str(zval *arg, zend_string **str, int type TSRMLS_DC);
698ZEND_API void zend_wrong_paramers_count_error(int num_args, int min_num_args, int max_num_args TSRMLS_DC);
699ZEND_API void zend_wrong_paramer_type_error(int num, zend_expected_type expected_type, zval *arg TSRMLS_DC);
700ZEND_API void zend_wrong_paramer_class_error(int num, char *name, zval *arg TSRMLS_DC);
701ZEND_API void zend_wrong_callback_error(int severity, int num, char *error TSRMLS_DC);
702ZEND_API int _z_param_class(zval *arg, zend_class_entry **pce, int num, int check_null TSRMLS_DC);
703
704#define ZPP_ERROR_OK             0
705#define ZPP_ERROR_FAILURE        1
706#define ZPP_ERROR_WRONG_CALLBACK 2
707#define ZPP_ERROR_WRONG_CLASS    3
708#define ZPP_ERROR_WRONG_ARG      4
709#define ZPP_ERROR_WRONG_COUNT    5
710
711#define ZEND_PARSE_PARAMETERS_START_EX(flags, min_num_args, max_num_args) do { \
712        const int _flags = (flags); \
713        int _min_num_args = (min_num_args); \
714        int _max_num_args = (max_num_args); \
715        int _num_args = EX(num_args); \
716        int _i; \
717        zval *_real_arg, *_arg = NULL; \
718        zend_expected_type _expected_type = IS_UNDEF; \
719        char *_error = NULL; \
720        zend_bool _dummy; \
721        zend_bool _optional = 0; \
722        int error_code = ZPP_ERROR_OK; \
723        ((void)_i); \
724        ((void)_real_arg); \
725        ((void)_arg); \
726        ((void)_expected_type); \
727        ((void)_error); \
728        ((void)_dummy); \
729        ((void)_optional); \
730        \
731        do { \
732            if (UNEXPECTED(_num_args < _min_num_args) || \
733                (UNEXPECTED(_num_args > _max_num_args) && \
734                 EXPECTED(_max_num_args >= 0))) { \
735                if (!(_flags & ZEND_PARSE_PARAMS_QUIET)) { \
736                    zend_wrong_paramers_count_error(_num_args, _min_num_args, _max_num_args TSRMLS_CC); \
737                } \
738                error_code = ZPP_ERROR_FAILURE; \
739                break; \
740            } \
741            _i = 0; \
742            _real_arg = ZEND_CALL_ARG(execute_data, 0);
743
744#define ZEND_PARSE_PARAMETERS_START(min_num_args, max_num_args) \
745    ZEND_PARSE_PARAMETERS_START_EX(0, min_num_args, max_num_args)
746
747#define ZEND_PARSE_PARAMETERS_END_EX(failure) \
748        } while (0); \
749        if (UNEXPECTED(error_code != ZPP_ERROR_OK)) { \
750            if (!(_flags & ZEND_PARSE_PARAMS_QUIET)) { \
751                if (error_code == ZPP_ERROR_WRONG_CALLBACK) { \
752                    zend_wrong_callback_error(E_WARNING, _i, _error TSRMLS_CC); \
753                } else if (error_code == ZPP_ERROR_WRONG_CLASS) { \
754                    zend_wrong_paramer_class_error(_i, _error, _arg TSRMLS_CC); \
755                } else if (error_code == ZPP_ERROR_WRONG_ARG) { \
756                    zend_wrong_paramer_type_error(_i, _expected_type, _arg TSRMLS_CC); \
757                } \
758            } \
759            failure; \
760        } \
761    } while (0)
762
763#define ZEND_PARSE_PARAMETERS_END() \
764    ZEND_PARSE_PARAMETERS_END_EX(return)
765
766#define Z_PARAM_PROLOGUE(separate) \
767    ++_i; \
768    if (_optional) { \
769        if (UNEXPECTED(_i >_num_args)) break; \
770    } \
771    _real_arg++; \
772    _arg = _real_arg; \
773    ZVAL_DEREF(_arg); \
774    if (separate) { \
775        SEPARATE_ZVAL_NOREF(_arg); \
776    }
777
778/* old "|" */
779#define Z_PARAM_OPTIONAL \
780    _optional = 1;
781
782/* old "a" */
783#define Z_PARAM_ARRAY_EX(dest, check_null, separate) \
784        Z_PARAM_PROLOGUE(separate); \
785        if (UNEXPECTED(!_z_param_array(_arg, &dest, check_null, 0))) { \
786            _expected_type = Z_EXPECTED_ARRAY; \
787            error_code = ZPP_ERROR_WRONG_ARG; \
788            break; \
789        }
790
791#define Z_PARAM_ARRAY(dest) \
792    Z_PARAM_ARRAY_EX(dest, 0, 0)
793
794/* old "A" */
795#define Z_PARAM_ARRAY_OR_OBJECT_EX(dest, check_null, separate) \
796        Z_PARAM_PROLOGUE(separate); \
797        if (UNEXPECTED(!_z_param_array(_arg, &dest, check_null, 1))) { \
798            _expected_type = Z_EXPECTED_ARRAY; \
799            error_code = ZPP_ERROR_WRONG_ARG; \
800            break; \
801        }
802
803#define Z_PARAM_ARRAY_OR_OBJECT(dest, check_null, separate) \
804    Z_PARAM_ARRAY_OR_OBJECT_EX(dest, 0, 0)
805
806/* old "b" */
807#define Z_PARAM_BOOL_EX(dest, is_null, check_null, separate) \
808        Z_PARAM_PROLOGUE(separate); \
809        if (UNEXPECTED(!_z_param_bool(_arg, &dest, &is_null, check_null TSRMLS_CC))) { \
810            _expected_type = Z_EXPECTED_BOOL; \
811            error_code = ZPP_ERROR_WRONG_ARG; \
812            break; \
813        }
814
815#define Z_PARAM_BOOL(dest) \
816    Z_PARAM_BOOL_EX(dest, _dummy, 0, 0)
817
818/* old "C" */
819#define Z_PARAM_CLASS_EX(dest, check_null, separate) \
820        Z_PARAM_PROLOGUE(separate); \
821        if (UNEXPECTED(!_z_param_class(_arg, &dest, _i, check_null TSRMLS_CC))) { \
822            error_code = ZPP_ERROR_FAILURE; \
823            break; \
824        }
825
826#define Z_PARAM_CLASS(dest) \
827    Z_PARAM_CLASS_EX(dest, 0, 0)
828
829/* old "d" */
830#define Z_PARAM_DOUBLE_EX(dest, is_null, check_null, separate) \
831        Z_PARAM_PROLOGUE(separate); \
832        if (UNEXPECTED(!_z_param_double(_arg, &dest, &is_null, check_null))) { \
833            _expected_type = Z_EXPECTED_DOUBLE; \
834            error_code = ZPP_ERROR_WRONG_ARG; \
835            break; \
836        }
837
838#define Z_PARAM_DOUBLE(dest) \
839    Z_PARAM_DOUBLE_EX(dest, _dummy, 0, 0)
840
841/* old "f" */
842#define Z_PARAM_FUNC_EX(dest_fci, dest_fcc, check_null, separate) \
843        Z_PARAM_PROLOGUE(separate); \
844        if (UNEXPECTED(!_z_param_func(_arg, &dest_fci, &dest_fcc, check_null, &_error TSRMLS_CC))) { \
845            if (!_error) { \
846                _expected_type = Z_EXPECTED_FUNC; \
847                error_code = ZPP_ERROR_WRONG_ARG; \
848                break; \
849            } else { \
850                error_code = ZPP_ERROR_WRONG_CALLBACK; \
851                break; \
852            } \
853        } else if (UNEXPECTED(_error != NULL)) { \
854            zend_wrong_callback_error(E_STRICT, _i, _error TSRMLS_CC); \
855        }
856
857#define Z_PARAM_FUNC(dest_fci, dest_fcc) \
858    Z_PARAM_FUNC_EX(dest_fci, dest_fcc, 0, 0)
859
860/* old "h" */
861#define Z_PARAM_ARRAY_HT_EX(dest, check_null, separate) \
862        Z_PARAM_PROLOGUE(separate); \
863        if (UNEXPECTED(!_z_param_array_ht(_arg, &dest, check_null, 0 TSRMLS_CC))) { \
864            _expected_type = Z_EXPECTED_ARRAY; \
865            error_code = ZPP_ERROR_WRONG_ARG; \
866            break; \
867        }
868
869#define Z_PARAM_ARRAY_HT(dest) \
870    Z_PARAM_ARRAY_HT_EX(dest, 0, 0)
871
872/* old "H" */
873#define Z_PARAM_ARRAY_OR_OBJECT_HT_EX(dest, check_null, separate) \
874        Z_PARAM_PROLOGUE(separate); \
875        if (UNEXPECTED(!_z_param_array_ht(_arg, &dest, check_null, 1 TSRMLS_CC))) { \
876            _expected_type = Z_EXPECTED_ARRAY; \
877            error_code = ZPP_ERROR_WRONG_ARG; \
878            break; \
879        }
880
881#define Z_PARAM_ARRAY_OR_OBJECT_HT(dest) \
882    Z_PARAM_ARRAY_OR_OBJECT_HT_EX(dest, 0, 0)
883
884/* old "l" */
885#define Z_PARAM_LONG_EX(dest, is_null, check_null, separate) \
886        Z_PARAM_PROLOGUE(separate); \
887        if (UNEXPECTED(!_z_param_long(_arg, &dest, &is_null, check_null, 0))) { \
888            _expected_type = Z_EXPECTED_LONG; \
889            error_code = ZPP_ERROR_WRONG_ARG; \
890            break; \
891        }
892
893#define Z_PARAM_LONG(dest) \
894    Z_PARAM_LONG_EX(dest, _dummy, 0, 0)
895
896/* old "L" */
897#define Z_PARAM_STRICT_LONG_EX(dest, is_null, check_null, separate) \
898        Z_PARAM_PROLOGUE(separate); \
899        if (UNEXPECTED(!_z_param_long(_arg, &dest, &is_null, check_null, 1))) { \
900            _expected_type = Z_EXPECTED_LONG; \
901            error_code = ZPP_ERROR_WRONG_ARG; \
902            break; \
903        }
904
905#define Z_PARAM_STRICT_LONG(dest) \
906    Z_PARAM_STRICT_LONG_EX(dest, _dummy, 0, 0)
907
908/* old "o" */
909#define Z_PARAM_OBJECT_EX(dest, check_null, separate) \
910        Z_PARAM_PROLOGUE(separate); \
911        if (UNEXPECTED(!_z_param_object(_arg, &dest, NULL, check_null TSRMLS_CC))) { \
912            _expected_type = Z_EXPECTED_OBJECT; \
913            error_code = ZPP_ERROR_WRONG_ARG; \
914            break; \
915        }
916
917#define Z_PARAM_OBJECT(dest) \
918    Z_PARAM_OBJECT_EX(dest, 0, 0)
919
920/* old "O" */
921#define Z_PARAM_OBJECT_OF_CLASS_EX(dest, _ce, check_null, separate) \
922        Z_PARAM_PROLOGUE(separate); \
923        if (UNEXPECTED(!_z_param_object(_arg, &dest, _ce, check_null TSRMLS_CC))) { \
924            if (_ce) { \
925                _error = (_ce)->name->val; \
926                error_code = ZPP_ERROR_WRONG_CLASS; \
927                break; \
928            } else { \
929                _expected_type = Z_EXPECTED_OBJECT; \
930                error_code = ZPP_ERROR_WRONG_ARG; \
931                break; \
932            } \
933        }
934
935#define Z_PARAM_OBJECT_OF_CLASS(dest, _ce) \
936    Z_PARAM_OBJECT_OF_CLASS_EX(dest, _ce, 0, 0)
937
938/* old "p" */
939#define Z_PARAM_PATH_EX(dest, dest_len, check_null, separate) \
940        Z_PARAM_PROLOGUE(separate); \
941        if (UNEXPECTED(!_z_param_path(_arg, &dest, &dest_len, check_null TSRMLS_CC))) { \
942            _expected_type = Z_EXPECTED_PATH; \
943            error_code = ZPP_ERROR_WRONG_ARG; \
944            break; \
945        }
946
947#define Z_PARAM_PATH(dest, dest_len) \
948    Z_PARAM_PATH_EX(dest, dest_len, 0, 0)
949
950/* old "P" */
951#define Z_PARAM_PATH_STR_EX(dest, check_null, separate) \
952        Z_PARAM_PROLOGUE(separate); \
953        if (UNEXPECTED(!_z_param_path_str(_arg, &dest, check_null TSRMLS_CC))) { \
954            _expected_type = Z_EXPECTED_PATH; \
955            error_code = ZPP_ERROR_WRONG_ARG; \
956            break; \
957        }
958
959#define Z_PARAM_PATH_STR(dest) \
960    Z_PARAM_PATH_STR_EX(dest, 0, 0)
961
962/* old "r" */
963#define Z_PARAM_RESOURCE_EX(dest, check_null, separate) \
964        Z_PARAM_PROLOGUE(separate); \
965        if (UNEXPECTED(!_z_param_resource(_arg, &dest, check_null))) { \
966            _expected_type = Z_EXPECTED_RESOURCE; \
967            error_code = ZPP_ERROR_WRONG_ARG; \
968            break; \
969        }
970
971#define Z_PARAM_RESOURCE(dest) \
972    Z_PARAM_RESOURCE_EX(dest, 0, 0)
973
974/* old "s" */
975#define Z_PARAM_STRING_EX(dest, dest_len, check_null, separate) \
976        Z_PARAM_PROLOGUE(separate); \
977        if (UNEXPECTED(!_z_param_string(_arg, &dest, &dest_len, check_null TSRMLS_CC))) { \
978            _expected_type = Z_EXPECTED_STRING; \
979            error_code = ZPP_ERROR_WRONG_ARG; \
980            break; \
981        }
982
983#define Z_PARAM_STRING(dest, dest_len) \
984    Z_PARAM_STRING_EX(dest, dest_len, 0, 0)
985
986/* old "S" */
987#define Z_PARAM_STR_EX(dest, check_null, separate) \
988        Z_PARAM_PROLOGUE(separate); \
989        if (UNEXPECTED(!_z_param_str(_arg, &dest, check_null TSRMLS_CC))) { \
990            _expected_type = Z_EXPECTED_STRING; \
991            error_code = ZPP_ERROR_WRONG_ARG; \
992            break; \
993        }
994
995#define Z_PARAM_STR(dest) \
996    Z_PARAM_STR_EX(dest, 0, 0)
997
998/* old "z" */
999#define Z_PARAM_ZVAL_EX(dest, check_null, separate) \
1000        if (separate) { \
1001            Z_PARAM_PROLOGUE(separate); \
1002            _z_param_zval_deref(_arg, &dest, check_null); \
1003        } else { \
1004            if (UNEXPECTED(++_i >_num_args)) break; \
1005            _real_arg++; \
1006            _z_param_zval(_real_arg, &dest, check_null); \
1007        }
1008
1009#define Z_PARAM_ZVAL(dest) \
1010    Z_PARAM_ZVAL_EX(dest, 0, 0)
1011
1012/* old "z" (with dereference) */
1013#define Z_PARAM_ZVAL_DEREF_EX(dest, check_null, separate) \
1014        Z_PARAM_PROLOGUE(separate); \
1015        _z_param_zval_deref(_arg, &dest, check_null);
1016
1017#define Z_PARAM_ZVAL_DEREF(dest) \
1018    Z_PARAM_ZVAL_DEREF_EX(dest, 0, 0)
1019
1020/* old "+" and "*" */
1021#define Z_PARAM_VARIADIC_EX(spec, dest, dest_num, post_varargs) do { \
1022        int _num_varargs = _num_args - _i - (post_varargs); \
1023        if (EXPECTED(_num_varargs > 0)) { \
1024            dest = _real_arg + 1; \
1025            dest_num = _num_varargs; \
1026            _i += _num_varargs; \
1027            _real_arg += _num_varargs; \
1028        } else { \
1029            dest = NULL; \
1030            dest_num = 0; \
1031        } \
1032    } while (0);
1033
1034#define Z_PARAM_VARIADIC(spec, dest, dest_num) \
1035    Z_PARAM_VARIADIC_EX(spec, dest, dest_num, 0)
1036
1037/* Private part of new parameter parsing API */
1038
1039static zend_always_inline int _z_param_bool(zval *arg, zend_bool *dest, zend_bool *is_null, int check_null TSRMLS_DC)
1040{
1041    if (check_null) {
1042        *is_null = 0;
1043    }
1044    if (EXPECTED(Z_TYPE_P(arg) == IS_TRUE)) {
1045        *dest = 1;
1046    } else if (EXPECTED(Z_TYPE_P(arg) < IS_TRUE)) {
1047        if (check_null) {
1048            *is_null = (Z_TYPE_P(arg) == IS_NULL);
1049        }
1050        *dest = 0;
1051    } else if (EXPECTED(Z_TYPE_P(arg) <= IS_STRING)) {
1052        *dest = zend_is_true(arg TSRMLS_CC);
1053    } else {
1054        return 0;
1055    }
1056    return 1;
1057}
1058
1059static zend_always_inline int _z_param_long(zval *arg, zend_long *dest, zend_bool *is_null, int check_null, int strict)
1060{
1061    if (check_null) {
1062        *is_null = 0;
1063    }
1064    if (EXPECTED(Z_TYPE_P(arg) == IS_LONG)) {
1065        *dest = Z_LVAL_P(arg);
1066    } else if (EXPECTED(Z_TYPE_P(arg) == IS_DOUBLE)) {
1067        if (strict && UNEXPECTED(Z_DVAL_P(arg) > ZEND_LONG_MAX)) {
1068            *dest = ZEND_LONG_MAX;
1069        } else if (strict && UNEXPECTED(Z_DVAL_P(arg) < ZEND_LONG_MIN)) {
1070            *dest = ZEND_LONG_MIN;
1071        } else {
1072            *dest = zend_dval_to_lval(Z_DVAL_P(arg));
1073        }
1074    } else if (EXPECTED(Z_TYPE_P(arg) == IS_STRING)) {
1075        double d;
1076        int type;
1077
1078        if (UNEXPECTED((type = is_numeric_str_function(Z_STR_P(arg), dest, &d)) != IS_LONG)) {
1079            if (EXPECTED(type != 0)) {
1080                if (strict && UNEXPECTED(d > ZEND_LONG_MAX)) {
1081                    *dest = ZEND_LONG_MAX;
1082                } else if (strict && UNEXPECTED(d < ZEND_LONG_MIN)) {
1083                    *dest = ZEND_LONG_MIN;
1084                } else {
1085                    *dest = zend_dval_to_lval(d);
1086                }
1087            } else {
1088                return 0;
1089            }
1090        }
1091    } else if (EXPECTED(Z_TYPE_P(arg) < IS_TRUE)) {
1092        if (check_null) {
1093            *is_null = (Z_TYPE_P(arg) == IS_NULL);
1094        }
1095        *dest = 0;
1096    } else if (EXPECTED(Z_TYPE_P(arg) == IS_TRUE)) {
1097        *dest = 1;
1098    } else {
1099        return 0;
1100    }
1101    return 1;
1102}
1103
1104static zend_always_inline int _z_param_double(zval *arg, double *dest, zend_bool *is_null, int check_null)
1105{
1106    if (check_null) {
1107        *is_null = 0;
1108    }
1109    if (EXPECTED(Z_TYPE_P(arg) == IS_DOUBLE)) {
1110        *dest = Z_DVAL_P(arg);
1111    } else if (EXPECTED(Z_TYPE_P(arg) == IS_LONG)) {
1112        *dest = (double)Z_LVAL_P(arg);
1113    } else if (EXPECTED(Z_TYPE_P(arg) == IS_STRING)) {
1114        zend_long l;
1115        int type;
1116
1117        if (UNEXPECTED((type = is_numeric_str_function(Z_STR_P(arg), &l, dest)) != IS_DOUBLE)) {
1118            if (EXPECTED(type != 0)) {
1119                *dest = (double)(l);
1120            } else {
1121                return 0;
1122            }
1123        }
1124    } else if (EXPECTED(Z_TYPE_P(arg) < IS_TRUE)) {
1125        if (check_null) {
1126            *is_null = (Z_TYPE_P(arg) == IS_NULL);
1127        }
1128        *dest = 0.0;
1129    } else if (EXPECTED(Z_TYPE_P(arg) == IS_TRUE)) {
1130        *dest = 1.0;
1131    } else {
1132        return 0;
1133    }
1134    return 1;
1135}
1136
1137static zend_always_inline int _z_param_str(zval *arg, zend_string **dest, int check_null TSRMLS_DC)
1138{
1139    if (EXPECTED(Z_TYPE_P(arg) == IS_STRING)) {
1140        *dest = Z_STR_P(arg);
1141    } else if (EXPECTED(Z_TYPE_P(arg) < IS_STRING)) {
1142        if (check_null && UNEXPECTED(Z_TYPE_P(arg) == IS_NULL)) {
1143            *dest = NULL;
1144        } else {
1145            if (Z_COPYABLE_P(arg) && Z_REFCOUNT_P(arg) > 1) {
1146                Z_DELREF_P(arg);
1147                zval_copy_ctor_func(arg);
1148            }
1149            convert_to_string(arg);
1150            *dest = Z_STR_P(arg);
1151        }
1152    } else if (UNEXPECTED(Z_TYPE_P(arg) != IS_OBJECT) ||
1153               UNEXPECTED(parse_arg_object_to_str(arg, dest, IS_STRING TSRMLS_CC) != SUCCESS)) {
1154        return 0;
1155    }
1156    return 1;
1157}
1158
1159static zend_always_inline int _z_param_string(zval *arg, char **dest, size_t *dest_len, int check_null TSRMLS_DC)
1160{
1161    zend_string *str;
1162
1163    if (!_z_param_str(arg, &str, check_null TSRMLS_CC)) {
1164        return 0;
1165    }
1166    if (check_null && UNEXPECTED(!str)) {
1167        *dest = NULL;
1168        *dest_len = 0;
1169    } else {
1170        *dest = str->val;
1171        *dest_len = str->len;
1172    }
1173    return 1;
1174}
1175
1176static zend_always_inline int _z_param_path_str(zval *arg, zend_string **dest, int check_null TSRMLS_DC)
1177{
1178    if (!_z_param_str(arg, dest, check_null TSRMLS_CC) ||
1179        (check_null && UNEXPECTED(!(*dest)->val[0])) ||
1180        UNEXPECTED(CHECK_NULL_PATH((*dest)->val, (*dest)->len))) {
1181        return 0;
1182    }
1183    return 1;
1184}
1185
1186static zend_always_inline int _z_param_path(zval *arg, char **dest, size_t *dest_len, int check_null TSRMLS_DC)
1187{
1188    zend_string *str;
1189
1190    if (!_z_param_path_str(arg, &str, check_null TSRMLS_CC)) {
1191        return 0;
1192    }
1193    if (check_null && UNEXPECTED(!str)) {
1194        *dest = NULL;
1195        *dest_len = 0;
1196    } else {
1197        *dest = str->val;
1198        *dest_len = str->len;
1199    }
1200    return 1;
1201}
1202
1203static zend_always_inline int _z_param_array(zval *arg, zval **dest, int check_null, int or_object)
1204{
1205    if (EXPECTED(Z_TYPE_P(arg) == IS_ARRAY) ||
1206        (or_object && EXPECTED(Z_TYPE_P(arg) == IS_OBJECT))) {
1207        *dest = arg;
1208    } else if (check_null && EXPECTED(Z_TYPE_P(arg) == IS_NULL)) {
1209        *dest = NULL;
1210    } else {
1211        return 0;
1212    }
1213    return 1;
1214}
1215
1216static zend_always_inline int _z_param_array_ht(zval *arg, HashTable **dest, int check_null, int or_object TSRMLS_DC)
1217{
1218    if (EXPECTED(Z_TYPE_P(arg) == IS_ARRAY)) {
1219        *dest = Z_ARRVAL_P(arg);
1220    } else if (or_object && EXPECTED(Z_TYPE_P(arg) == IS_OBJECT)) {
1221        *dest = Z_OBJ_HT_P(arg)->get_properties(arg TSRMLS_CC);
1222    } else if (check_null && EXPECTED(Z_TYPE_P(arg) == IS_NULL)) {
1223        *dest = NULL;
1224    } else {
1225        return 0;
1226    }
1227    return 1;
1228}
1229
1230static zend_always_inline int _z_param_object(zval *arg, zval **dest, zend_class_entry *ce, int check_null TSRMLS_DC)
1231{
1232    if (EXPECTED(Z_TYPE_P(arg) == IS_OBJECT) &&
1233        (!ce || EXPECTED(instanceof_function(Z_OBJCE_P(arg), ce TSRMLS_CC) != 0))) {
1234        *dest = arg;
1235    } else if (check_null && EXPECTED(Z_TYPE_P(arg) == IS_NULL)) {
1236        *dest = NULL;
1237    } else {
1238        return 0;
1239    }
1240    return 1;
1241}
1242
1243static zend_always_inline int _z_param_resource(zval *arg, zval **dest, int check_null)
1244{
1245    if (EXPECTED(Z_TYPE_P(arg) == IS_RESOURCE)) {
1246        *dest = arg;
1247    } else if (check_null && EXPECTED(Z_TYPE_P(arg) == IS_NULL)) {
1248        *dest = NULL;
1249    } else {
1250        return 0;
1251    }
1252    return 1;
1253}
1254
1255static zend_always_inline int _z_param_func(zval *arg, zend_fcall_info *dest_fci, zend_fcall_info_cache *dest_fcc, int check_null, char **error TSRMLS_DC)
1256{
1257    if (check_null && UNEXPECTED(Z_TYPE_P(arg) == IS_NULL)) {
1258        dest_fci->size = 0;
1259        dest_fcc->initialized = 0;
1260        *error = NULL;
1261    } else if (UNEXPECTED(zend_fcall_info_init(arg, 0, dest_fci, dest_fcc, NULL, error TSRMLS_CC) != SUCCESS)) {
1262        return 0;
1263    }
1264    return 1;
1265}
1266
1267static zend_always_inline void _z_param_zval(zval *arg, zval **dest, int check_null)
1268{
1269    *dest = (check_null &&
1270        (UNEXPECTED(Z_TYPE_P(arg) == IS_NULL) ||
1271         (UNEXPECTED(Z_ISREF_P(arg)) &&
1272          UNEXPECTED(Z_TYPE_P(Z_REFVAL_P(arg)) == IS_NULL)))) ? NULL : arg;
1273}
1274
1275static zend_always_inline void _z_param_zval_deref(zval *arg, zval **dest, int check_null)
1276{
1277    *dest = (check_null && UNEXPECTED(Z_TYPE_P(arg) == IS_NULL)) ? NULL : arg;
1278}
1279
1280#endif /* FAST_ZPP */
1281
1282/* End of new parameter parsing API */
1283
1284END_EXTERN_C()
1285
1286#endif /* ZEND_API_H */
1287
1288
1289/*
1290 * Local variables:
1291 * tab-width: 4
1292 * c-basic-offset: 4
1293 * indent-tabs-mode: t
1294 * End:
1295 */
1296