113d840bcSZeev Suraski/*
213d840bcSZeev Suraski   +----------------------------------------------------------------------+
313d840bcSZeev Suraski   | Zend Engine                                                          |
413d840bcSZeev Suraski   +----------------------------------------------------------------------+
5a6519d05SXinchen Hui   | Copyright (c) 1998-2018 Zend Technologies Ltd. (http://www.zend.com) |
613d840bcSZeev Suraski   +----------------------------------------------------------------------+
7d863d52aSSebastian Bergmann   | This source file is subject to version 2.00 of the Zend license,     |
813d840bcSZeev Suraski   | that is bundled with this package in the file LICENSE, and is        |
9f68c7ff2SJames Cox   | available through the world-wide-web at the following url:           |
10d863d52aSSebastian Bergmann   | http://www.zend.com/license/2_00.txt.                                |
1113d840bcSZeev Suraski   | If you did not receive a copy of the Zend license and are unable to  |
1213d840bcSZeev Suraski   | obtain it through the world-wide-web, please send a note to          |
1313d840bcSZeev Suraski   | license@zend.com so we can mail you a copy immediately.              |
1413d840bcSZeev Suraski   +----------------------------------------------------------------------+
159afce019SZeev Suraski   | Authors: Andi Gutmans <andi@php.net>                                 |
169afce019SZeev Suraski   |          Zeev Suraski <zeev@php.net>                                 |
1713d840bcSZeev Suraski   +----------------------------------------------------------------------+
1813d840bcSZeev Suraski*/
1913d840bcSZeev Suraski
2013d840bcSZeev Suraski#include "zend.h"
2113d840bcSZeev Suraski#include "zend_API.h"
222afc8373SDmitry Stogov#include "zend_gc.h"
2313d840bcSZeev Suraski#include "zend_builtin_functions.h"
2468217ef5SAndi Gutmans#include "zend_constants.h"
254be862b0SZeev Suraski#include "zend_ini.h"
2650ea2676SMarcus Boerger#include "zend_exceptions.h"
27ebaba407SJohannes Schlüter#include "zend_extensions.h"
28ba0486f9SFelipe Pena#include "zend_closures.h"
29b4a142abSBob Weinand#include "zend_generators.h"
30957aeb83SIlia Alshanetsky
3113d840bcSZeev Suraskistatic ZEND_FUNCTION(zend_version);
32a30f028aSZeev Suraskistatic ZEND_FUNCTION(func_num_args);
33a30f028aSZeev Suraskistatic ZEND_FUNCTION(func_get_arg);
34a30f028aSZeev Suraskistatic ZEND_FUNCTION(func_get_args);
3534742e3fSFelipe Penastatic ZEND_FUNCTION(strlen);
3606a18f16SAndi Gutmansstatic ZEND_FUNCTION(strcmp);
37c2fd6752SAndrei Zmievskistatic ZEND_FUNCTION(strncmp);
3806a18f16SAndi Gutmansstatic ZEND_FUNCTION(strcasecmp);
391373a162SStanislav Malyshevstatic ZEND_FUNCTION(strncasecmp);
4006a18f16SAndi Gutmansstatic ZEND_FUNCTION(each);
4106a18f16SAndi Gutmansstatic ZEND_FUNCTION(error_reporting);
4268217ef5SAndi Gutmansstatic ZEND_FUNCTION(define);
4368217ef5SAndi Gutmansstatic ZEND_FUNCTION(defined);
4468217ef5SAndi Gutmansstatic ZEND_FUNCTION(get_class);
45166266dfSDmitry Stogovstatic ZEND_FUNCTION(get_called_class);
4668217ef5SAndi Gutmansstatic ZEND_FUNCTION(get_parent_class);
4768217ef5SAndi Gutmansstatic ZEND_FUNCTION(method_exists);
4832182b19SMarcus Boergerstatic ZEND_FUNCTION(property_exists);
493fdf0dbeSAndrei Zmievskistatic ZEND_FUNCTION(class_exists);
50709c5bd2SAndi Gutmansstatic ZEND_FUNCTION(interface_exists);
51478e5d1dSStefan Marrstatic ZEND_FUNCTION(trait_exists);
523fdf0dbeSAndrei Zmievskistatic ZEND_FUNCTION(function_exists);
53907fa665SDmitry Stogovstatic ZEND_FUNCTION(class_alias);
545951b166SAndi Gutmansstatic ZEND_FUNCTION(get_included_files);
55c9c6446aSAndrei Zmievskistatic ZEND_FUNCTION(is_subclass_of);
56031784c6SSebastian Bergmannstatic ZEND_FUNCTION(is_a);
57685fd429SAndrei Zmievskistatic ZEND_FUNCTION(get_class_vars);
58685fd429SAndrei Zmievskistatic ZEND_FUNCTION(get_object_vars);
5940e99c5eSAndrei Zmievskistatic ZEND_FUNCTION(get_class_methods);
60746f0180SZeev Suraskistatic ZEND_FUNCTION(trigger_error);
61746f0180SZeev Suraskistatic ZEND_FUNCTION(set_error_handler);
6234c2b0a0SZeev Suraskistatic ZEND_FUNCTION(restore_error_handler);
6304788f95SStig Bakkenstatic ZEND_FUNCTION(set_exception_handler);
6404788f95SStig Bakkenstatic ZEND_FUNCTION(restore_exception_handler);
65164e4e50SAndrei Zmievskistatic ZEND_FUNCTION(get_declared_classes);
6600eec093SFelipe Penastatic ZEND_FUNCTION(get_declared_traits);
67dc6a849aSStanislav Malyshevstatic ZEND_FUNCTION(get_declared_interfaces);
685c6593b5SAndi Gutmansstatic ZEND_FUNCTION(get_defined_functions);
695c6593b5SAndi Gutmansstatic ZEND_FUNCTION(get_defined_vars);
70b7a8baf1SZeev Suraskistatic ZEND_FUNCTION(create_function);
7155d313dbSZeev Suraskistatic ZEND_FUNCTION(get_resource_type);
72d37820ffSDmitry Stogovstatic ZEND_FUNCTION(get_resources);
734d78270bSAndrei Zmievskistatic ZEND_FUNCTION(get_loaded_extensions);
744d78270bSAndrei Zmievskistatic ZEND_FUNCTION(extension_loaded);
754d78270bSAndrei Zmievskistatic ZEND_FUNCTION(get_extension_funcs);
764d78270bSAndrei Zmievskistatic ZEND_FUNCTION(get_defined_constants);
777e5ec2d7SAndi Gutmansstatic ZEND_FUNCTION(debug_backtrace);
7827de54b0SAndi Gutmansstatic ZEND_FUNCTION(debug_print_backtrace);
79b3ca0c25SNikita Popov#if ZEND_DEBUG && defined(ZTS)
807dfa4391SZeev Suraskistatic ZEND_FUNCTION(zend_thread_id);
81fddf89afSZeev Suraski#endif
82668ecaa6SDmitry Stogovstatic ZEND_FUNCTION(gc_mem_caches);
8371592cecSDmitry Stogovstatic ZEND_FUNCTION(gc_collect_cycles);
8471592cecSDmitry Stogovstatic ZEND_FUNCTION(gc_enabled);
8571592cecSDmitry Stogovstatic ZEND_FUNCTION(gc_enable);
8671592cecSDmitry Stogovstatic ZEND_FUNCTION(gc_disable);
872afc8373SDmitry Stogovstatic ZEND_FUNCTION(gc_status);
8813d840bcSZeev Suraski
89816e66a8SFelipe Pena/* {{{ arginfo */
9082b92cfaSDmitry StogovZEND_BEGIN_ARG_INFO(arginfo_zend__void, 0)
9182b92cfaSDmitry StogovZEND_END_ARG_INFO()
9282b92cfaSDmitry Stogov
93816e66a8SFelipe PenaZEND_BEGIN_ARG_INFO_EX(arginfo_func_get_arg, 0, 0, 1)
94ed418312SDmitry Stogov	ZEND_ARG_INFO(0, arg_num)
95816e66a8SFelipe PenaZEND_END_ARG_INFO()
96816e66a8SFelipe Pena
97ed418312SDmitry StogovZEND_BEGIN_ARG_INFO_EX(arginfo_strlen, 0, 0, 1)
98ed418312SDmitry Stogov	ZEND_ARG_INFO(0, str)
99816e66a8SFelipe PenaZEND_END_ARG_INFO()
100816e66a8SFelipe Pena
101ed418312SDmitry StogovZEND_BEGIN_ARG_INFO_EX(arginfo_strcmp, 0, 0, 2)
102ed418312SDmitry Stogov	ZEND_ARG_INFO(0, str1)
103ed418312SDmitry Stogov	ZEND_ARG_INFO(0, str2)
104816e66a8SFelipe PenaZEND_END_ARG_INFO()
105816e66a8SFelipe Pena
106ed418312SDmitry StogovZEND_BEGIN_ARG_INFO_EX(arginfo_strncmp, 0, 0, 3)
107ed418312SDmitry Stogov	ZEND_ARG_INFO(0, str1)
108ed418312SDmitry Stogov	ZEND_ARG_INFO(0, str2)
109ed418312SDmitry Stogov	ZEND_ARG_INFO(0, len)
110816e66a8SFelipe PenaZEND_END_ARG_INFO()
111816e66a8SFelipe Pena
112ed418312SDmitry StogovZEND_BEGIN_ARG_INFO_EX(arginfo_each, 0, 0, 1)
113ed418312SDmitry Stogov	ZEND_ARG_INFO(1, arr)
114816e66a8SFelipe PenaZEND_END_ARG_INFO()
115816e66a8SFelipe Pena
116ed418312SDmitry StogovZEND_BEGIN_ARG_INFO_EX(arginfo_error_reporting, 0, 0, 0)
117ed418312SDmitry Stogov	ZEND_ARG_INFO(0, new_error_level)
118816e66a8SFelipe PenaZEND_END_ARG_INFO()
119816e66a8SFelipe Pena
1201201be39SRasmus LerdorfZEND_BEGIN_ARG_INFO_EX(arginfo_define, 0, 0, 2)
121ed418312SDmitry Stogov	ZEND_ARG_INFO(0, constant_name)
122816e66a8SFelipe Pena	ZEND_ARG_INFO(0, value)
123ed418312SDmitry Stogov	ZEND_ARG_INFO(0, case_insensitive)
124816e66a8SFelipe PenaZEND_END_ARG_INFO()
125816e66a8SFelipe Pena
126ed418312SDmitry StogovZEND_BEGIN_ARG_INFO_EX(arginfo_defined, 0, 0, 1)
127ed418312SDmitry Stogov	ZEND_ARG_INFO(0, constant_name)
128816e66a8SFelipe PenaZEND_END_ARG_INFO()
129816e66a8SFelipe Pena
130ed418312SDmitry StogovZEND_BEGIN_ARG_INFO_EX(arginfo_get_class, 0, 0, 0)
131816e66a8SFelipe Pena	ZEND_ARG_INFO(0, object)
132816e66a8SFelipe PenaZEND_END_ARG_INFO()
133816e66a8SFelipe Pena
134ed418312SDmitry StogovZEND_BEGIN_ARG_INFO_EX(arginfo_is_subclass_of, 0, 0, 2)
135816e66a8SFelipe Pena	ZEND_ARG_INFO(0, object)
136ed418312SDmitry Stogov	ZEND_ARG_INFO(0, class_name)
137ed418312SDmitry Stogov	ZEND_ARG_INFO(0, allow_string)
138816e66a8SFelipe PenaZEND_END_ARG_INFO()
139816e66a8SFelipe Pena
140ed418312SDmitry StogovZEND_BEGIN_ARG_INFO_EX(arginfo_get_class_vars, 0, 0, 1)
141ed418312SDmitry Stogov	ZEND_ARG_INFO(0, class_name)
142816e66a8SFelipe PenaZEND_END_ARG_INFO()
143816e66a8SFelipe Pena
144ed418312SDmitry StogovZEND_BEGIN_ARG_INFO_EX(arginfo_get_object_vars, 0, 0, 1)
145816e66a8SFelipe Pena	ZEND_ARG_INFO(0, obj)
146816e66a8SFelipe PenaZEND_END_ARG_INFO()
147816e66a8SFelipe Pena
148ed418312SDmitry StogovZEND_BEGIN_ARG_INFO_EX(arginfo_get_class_methods, 0, 0, 1)
149816e66a8SFelipe Pena	ZEND_ARG_INFO(0, class)
150816e66a8SFelipe PenaZEND_END_ARG_INFO()
151816e66a8SFelipe Pena
152ed418312SDmitry StogovZEND_BEGIN_ARG_INFO_EX(arginfo_method_exists, 0, 0, 2)
153816e66a8SFelipe Pena	ZEND_ARG_INFO(0, object)
154ed418312SDmitry Stogov	ZEND_ARG_INFO(0, method)
155816e66a8SFelipe PenaZEND_END_ARG_INFO()
156816e66a8SFelipe Pena
157ed418312SDmitry StogovZEND_BEGIN_ARG_INFO_EX(arginfo_property_exists, 0, 0, 2)
158816e66a8SFelipe Pena	ZEND_ARG_INFO(0, object_or_class)
159ed418312SDmitry Stogov	ZEND_ARG_INFO(0, property_name)
160816e66a8SFelipe PenaZEND_END_ARG_INFO()
161816e66a8SFelipe Pena
162ed418312SDmitry StogovZEND_BEGIN_ARG_INFO_EX(arginfo_class_exists, 0, 0, 1)
163ed418312SDmitry Stogov	ZEND_ARG_INFO(0, classname)
164ed418312SDmitry Stogov	ZEND_ARG_INFO(0, autoload)
165816e66a8SFelipe PenaZEND_END_ARG_INFO()
166816e66a8SFelipe Pena
167ed418312SDmitry StogovZEND_BEGIN_ARG_INFO_EX(arginfo_trait_exists, 0, 0, 1)
168ed418312SDmitry Stogov	ZEND_ARG_INFO(0, traitname)
169ed418312SDmitry Stogov	ZEND_ARG_INFO(0, autoload)
170478e5d1dSStefan MarrZEND_END_ARG_INFO()
171478e5d1dSStefan Marr
172ed418312SDmitry StogovZEND_BEGIN_ARG_INFO_EX(arginfo_function_exists, 0, 0, 1)
173ed418312SDmitry Stogov	ZEND_ARG_INFO(0, function_name)
174816e66a8SFelipe PenaZEND_END_ARG_INFO()
175816e66a8SFelipe Pena
176ed418312SDmitry StogovZEND_BEGIN_ARG_INFO_EX(arginfo_class_alias, 0, 0, 2)
177ed418312SDmitry Stogov	ZEND_ARG_INFO(0, user_class_name)
178ed418312SDmitry Stogov	ZEND_ARG_INFO(0, alias_name)
179ed418312SDmitry Stogov	ZEND_ARG_INFO(0, autoload)
180816e66a8SFelipe PenaZEND_END_ARG_INFO()
181816e66a8SFelipe Pena
182816e66a8SFelipe PenaZEND_BEGIN_ARG_INFO_EX(arginfo_trigger_error, 0, 0, 1)
183ed418312SDmitry Stogov	ZEND_ARG_INFO(0, message)
184ed418312SDmitry Stogov	ZEND_ARG_INFO(0, error_type)
185816e66a8SFelipe PenaZEND_END_ARG_INFO()
186816e66a8SFelipe Pena
187ed418312SDmitry StogovZEND_BEGIN_ARG_INFO_EX(arginfo_set_error_handler, 0, 0, 1)
188ed418312SDmitry Stogov	ZEND_ARG_INFO(0, error_handler)
189ed418312SDmitry Stogov	ZEND_ARG_INFO(0, error_types)
190816e66a8SFelipe PenaZEND_END_ARG_INFO()
191816e66a8SFelipe Pena
192ed418312SDmitry StogovZEND_BEGIN_ARG_INFO_EX(arginfo_set_exception_handler, 0, 0, 1)
193ed418312SDmitry Stogov	ZEND_ARG_INFO(0, exception_handler)
194816e66a8SFelipe PenaZEND_END_ARG_INFO()
195816e66a8SFelipe Pena
196a843a86eSGabriel CarusoZEND_BEGIN_ARG_INFO_EX(arginfo_get_defined_functions, 0, 0, 0)
197ff6f41c9SXinchen Hui	ZEND_ARG_INFO(0, exclude_disabled)
198ff6f41c9SXinchen HuiZEND_END_ARG_INFO()
199ff6f41c9SXinchen Hui
200ed418312SDmitry StogovZEND_BEGIN_ARG_INFO_EX(arginfo_create_function, 0, 0, 2)
201ed418312SDmitry Stogov	ZEND_ARG_INFO(0, args)
202ed418312SDmitry Stogov	ZEND_ARG_INFO(0, code)
203816e66a8SFelipe PenaZEND_END_ARG_INFO()
204816e66a8SFelipe Pena
205ed418312SDmitry StogovZEND_BEGIN_ARG_INFO_EX(arginfo_get_resource_type, 0, 0, 1)
206ed418312SDmitry Stogov	ZEND_ARG_INFO(0, res)
207816e66a8SFelipe PenaZEND_END_ARG_INFO()
208816e66a8SFelipe Pena
209ed418312SDmitry StogovZEND_BEGIN_ARG_INFO_EX(arginfo_get_resources, 0, 0, 0)
210ed418312SDmitry Stogov	ZEND_ARG_INFO(0, type)
211d37820ffSDmitry StogovZEND_END_ARG_INFO()
212d37820ffSDmitry Stogov
213ed418312SDmitry StogovZEND_BEGIN_ARG_INFO_EX(arginfo_get_loaded_extensions, 0, 0, 0)
214ed418312SDmitry Stogov	ZEND_ARG_INFO(0, zend_extensions)
215816e66a8SFelipe PenaZEND_END_ARG_INFO()
216816e66a8SFelipe Pena
217ed418312SDmitry StogovZEND_BEGIN_ARG_INFO_EX(arginfo_get_defined_constants, 0, 0, 0)
218ed418312SDmitry Stogov	ZEND_ARG_INFO(0, categorize)
219816e66a8SFelipe PenaZEND_END_ARG_INFO()
220816e66a8SFelipe Pena
221ed418312SDmitry StogovZEND_BEGIN_ARG_INFO_EX(arginfo_debug_backtrace, 0, 0, 0)
222ed418312SDmitry Stogov	ZEND_ARG_INFO(0, options)
223ed418312SDmitry Stogov	ZEND_ARG_INFO(0, limit)
2246f3148dbSSebastian BergmannZEND_END_ARG_INFO()
2256f3148dbSSebastian Bergmann
2266f3148dbSSebastian BergmannZEND_BEGIN_ARG_INFO_EX(arginfo_debug_print_backtrace, 0, 0, 0)
227ed418312SDmitry Stogov	ZEND_ARG_INFO(0, options)
228324d5ecbSRasmus Lerdorf	ZEND_ARG_INFO(0, limit)
229816e66a8SFelipe PenaZEND_END_ARG_INFO()
230816e66a8SFelipe Pena
231ed418312SDmitry StogovZEND_BEGIN_ARG_INFO_EX(arginfo_extension_loaded, 0, 0, 1)
232ed418312SDmitry Stogov	ZEND_ARG_INFO(0, extension_name)
233816e66a8SFelipe PenaZEND_END_ARG_INFO()
2342c84006fSReeze Xia
235145555f8SXinchen Hui/* }}} */
236145555f8SXinchen Hui
237ff037203SMarcus Boergerstatic const zend_function_entry builtin_functions[] = { /* {{{ */
23882b92cfaSDmitry Stogov	ZEND_FE(zend_version,		arginfo_zend__void)
23982b92cfaSDmitry Stogov	ZEND_FE(func_num_args,		arginfo_zend__void)
240816e66a8SFelipe Pena	ZEND_FE(func_get_arg,		arginfo_func_get_arg)
24182b92cfaSDmitry Stogov	ZEND_FE(func_get_args,		arginfo_zend__void)
242dd200553SJefersson Nathan	ZEND_FE(strlen,			arginfo_strlen)
243dd200553SJefersson Nathan	ZEND_FE(strcmp,			arginfo_strcmp)
244dd200553SJefersson Nathan	ZEND_FE(strncmp,		arginfo_strncmp)
245dd200553SJefersson Nathan	ZEND_FE(strcasecmp,		arginfo_strcmp)
24634742e3fSFelipe Pena	ZEND_FE(strncasecmp,		arginfo_strncmp)
247dd200553SJefersson Nathan	ZEND_FE(each,			arginfo_each)
248816e66a8SFelipe Pena	ZEND_FE(error_reporting,	arginfo_error_reporting)
249dd200553SJefersson Nathan	ZEND_FE(define,			arginfo_define)
250dd200553SJefersson Nathan	ZEND_FE(defined,		arginfo_defined)
251dd200553SJefersson Nathan	ZEND_FE(get_class,		arginfo_get_class)
25282b92cfaSDmitry Stogov	ZEND_FE(get_called_class,	arginfo_zend__void)
25334742e3fSFelipe Pena	ZEND_FE(get_parent_class,	arginfo_get_class)
254816e66a8SFelipe Pena	ZEND_FE(method_exists,		arginfo_method_exists)
255816e66a8SFelipe Pena	ZEND_FE(property_exists,	arginfo_property_exists)
256816e66a8SFelipe Pena	ZEND_FE(class_exists,		arginfo_class_exists)
25734742e3fSFelipe Pena	ZEND_FE(interface_exists,	arginfo_class_exists)
258478e5d1dSStefan Marr	ZEND_FE(trait_exists,		arginfo_trait_exists)
259816e66a8SFelipe Pena	ZEND_FE(function_exists,	arginfo_function_exists)
260816e66a8SFelipe Pena	ZEND_FE(class_alias,		arginfo_class_alias)
26182b92cfaSDmitry Stogov	ZEND_FE(get_included_files,	arginfo_zend__void)
26282b92cfaSDmitry Stogov	ZEND_FALIAS(get_required_files,	get_included_files,		arginfo_zend__void)
263816e66a8SFelipe Pena	ZEND_FE(is_subclass_of,		arginfo_is_subclass_of)
264dd200553SJefersson Nathan	ZEND_FE(is_a,			arginfo_is_subclass_of)
265816e66a8SFelipe Pena	ZEND_FE(get_class_vars,		arginfo_get_class_vars)
266816e66a8SFelipe Pena	ZEND_FE(get_object_vars,	arginfo_get_object_vars)
267816e66a8SFelipe Pena	ZEND_FE(get_class_methods,	arginfo_get_class_methods)
268816e66a8SFelipe Pena	ZEND_FE(trigger_error,		arginfo_trigger_error)
269816e66a8SFelipe Pena	ZEND_FALIAS(user_error,		trigger_error,		arginfo_trigger_error)
270dd200553SJefersson Nathan	ZEND_FE(set_error_handler,		arginfo_set_error_handler)
27182b92cfaSDmitry Stogov	ZEND_FE(restore_error_handler,		arginfo_zend__void)
272816e66a8SFelipe Pena	ZEND_FE(set_exception_handler,		arginfo_set_exception_handler)
27382b92cfaSDmitry Stogov	ZEND_FE(restore_exception_handler,	arginfo_zend__void)
27482b92cfaSDmitry Stogov	ZEND_FE(get_declared_classes, 		arginfo_zend__void)
27582b92cfaSDmitry Stogov	ZEND_FE(get_declared_traits, 		arginfo_zend__void)
27682b92cfaSDmitry Stogov	ZEND_FE(get_declared_interfaces, 	arginfo_zend__void)
277ff6f41c9SXinchen Hui	ZEND_FE(get_defined_functions, 		arginfo_get_defined_functions)
27882b92cfaSDmitry Stogov	ZEND_FE(get_defined_vars,		arginfo_zend__void)
279eaeecc52SNikita Popov	ZEND_DEP_FE(create_function,		arginfo_create_function)
280dd200553SJefersson Nathan	ZEND_FE(get_resource_type,		arginfo_get_resource_type)
281d37820ffSDmitry Stogov	ZEND_FE(get_resources,			arginfo_get_resources)
282816e66a8SFelipe Pena	ZEND_FE(get_loaded_extensions,		arginfo_get_loaded_extensions)
283dd200553SJefersson Nathan	ZEND_FE(extension_loaded,		arginfo_extension_loaded)
28434742e3fSFelipe Pena	ZEND_FE(get_extension_funcs,		arginfo_extension_loaded)
285816e66a8SFelipe Pena	ZEND_FE(get_defined_constants,		arginfo_get_defined_constants)
286dd200553SJefersson Nathan	ZEND_FE(debug_backtrace, 		arginfo_debug_backtrace)
2876f3148dbSSebastian Bergmann	ZEND_FE(debug_print_backtrace, 		arginfo_debug_print_backtrace)
288b3ca0c25SNikita Popov#if ZEND_DEBUG && defined(ZTS)
2897dfa4391SZeev Suraski	ZEND_FE(zend_thread_id,		NULL)
290fddf89afSZeev Suraski#endif
291668ecaa6SDmitry Stogov	ZEND_FE(gc_mem_caches,      arginfo_zend__void)
29282b92cfaSDmitry Stogov	ZEND_FE(gc_collect_cycles, 	arginfo_zend__void)
29382b92cfaSDmitry Stogov	ZEND_FE(gc_enabled, 		arginfo_zend__void)
29482b92cfaSDmitry Stogov	ZEND_FE(gc_enable, 		arginfo_zend__void)
29582b92cfaSDmitry Stogov	ZEND_FE(gc_disable, 		arginfo_zend__void)
2962afc8373SDmitry Stogov	ZEND_FE(gc_status, 		arginfo_zend__void)
297468d1351SFelipe Pena	ZEND_FE_END
29813d840bcSZeev Suraski};
299ff037203SMarcus Boerger/* }}} */
30013d840bcSZeev Suraski
30163d00f70SMarcus BoergerZEND_MINIT_FUNCTION(core) { /* {{{ */
30263d00f70SMarcus Boerger	zend_class_entry class_entry;
30363d00f70SMarcus Boerger
30463d00f70SMarcus Boerger	INIT_CLASS_ENTRY(class_entry, "stdClass", NULL);
305bdeb220fSAnatol Belski	zend_standard_class_def = zend_register_internal_class(&class_entry);
30663d00f70SMarcus Boerger
307bdeb220fSAnatol Belski	zend_register_default_classes();
3088797aa99SMarcus Boerger
30963d00f70SMarcus Boerger	return SUCCESS;
31063d00f70SMarcus Boerger}
31163d00f70SMarcus Boerger/* }}} */
31263d00f70SMarcus Boerger
313ff037203SMarcus Boergerzend_module_entry zend_builtin_module = { /* {{{ */
314ff037203SMarcus Boerger    STANDARD_MODULE_HEADER,
315826cc0dcSMarcus Boerger	"Core",
316ff037203SMarcus Boerger	builtin_functions,
31763d00f70SMarcus Boerger	ZEND_MINIT(core),
318ff037203SMarcus Boerger	NULL,
319ff037203SMarcus Boerger	NULL,
320ff037203SMarcus Boerger	NULL,
321ff037203SMarcus Boerger	NULL,
322ff037203SMarcus Boerger	ZEND_VERSION,
323ff037203SMarcus Boerger	STANDARD_MODULE_PROPERTIES
324ff037203SMarcus Boerger};
325ff037203SMarcus Boerger/* }}} */
32613d840bcSZeev Suraski
327bdeb220fSAnatol Belskiint zend_startup_builtin_functions(void) /* {{{ */
32813d840bcSZeev Suraski{
329826cc0dcSMarcus Boerger	zend_builtin_module.module_number = 0;
330826cc0dcSMarcus Boerger	zend_builtin_module.type = MODULE_PERSISTENT;
331bdeb220fSAnatol Belski	return (EG(current_module) = zend_register_module_ex(&zend_builtin_module)) == NULL ? FAILURE : SUCCESS;
33213d840bcSZeev Suraski}
333ff037203SMarcus Boerger/* }}} */
33413d840bcSZeev Suraski
33554767061SAndi Gutmans/* {{{ proto string zend_version(void)
33654767061SAndi Gutmans   Get the version of the Zend Engine */
33713d840bcSZeev SuraskiZEND_FUNCTION(zend_version)
33813d840bcSZeev Suraski{
3396c630eefSChristoph M. Becker	if (zend_parse_parameters_none() == FAILURE) {
3406c630eefSChristoph M. Becker		return;
3416c630eefSChristoph M. Becker	}
3426c630eefSChristoph M. Becker
343f4cfaf36SDmitry Stogov	RETURN_STRINGL(ZEND_VERSION, sizeof(ZEND_VERSION)-1);
34413d840bcSZeev Suraski}
34554767061SAndi Gutmans/* }}} */
3467a4a5944SZeev Suraski
347668ecaa6SDmitry Stogov/* {{{ proto int gc_mem_caches(void)
348668ecaa6SDmitry Stogov   Reclaims memory used by MM caches.
349668ecaa6SDmitry Stogov   Returns number of freed bytes */
350668ecaa6SDmitry StogovZEND_FUNCTION(gc_mem_caches)
351668ecaa6SDmitry Stogov{
3526c630eefSChristoph M. Becker	if (zend_parse_parameters_none() == FAILURE) {
3536c630eefSChristoph M. Becker		return;
3546c630eefSChristoph M. Becker	}
3556c630eefSChristoph M. Becker
356668ecaa6SDmitry Stogov	RETURN_LONG(zend_mm_gc(zend_mm_get_heap()));
357668ecaa6SDmitry Stogov}
358668ecaa6SDmitry Stogov/* }}} */
359668ecaa6SDmitry Stogov
36071592cecSDmitry Stogov/* {{{ proto int gc_collect_cycles(void)
36171592cecSDmitry Stogov   Forces collection of any existing garbage cycles.
36271592cecSDmitry Stogov   Returns number of freed zvals */
36371592cecSDmitry StogovZEND_FUNCTION(gc_collect_cycles)
36471592cecSDmitry Stogov{
3656c630eefSChristoph M. Becker	if (zend_parse_parameters_none() == FAILURE) {
3666c630eefSChristoph M. Becker		return;
3676c630eefSChristoph M. Becker	}
3686c630eefSChristoph M. Becker
369bdeb220fSAnatol Belski	RETURN_LONG(gc_collect_cycles());
37071592cecSDmitry Stogov}
37171592cecSDmitry Stogov/* }}} */
37271592cecSDmitry Stogov
37371592cecSDmitry Stogov/* {{{ proto void gc_enabled(void)
37471592cecSDmitry Stogov   Returns status of the circular reference collector */
37571592cecSDmitry StogovZEND_FUNCTION(gc_enabled)
37671592cecSDmitry Stogov{
3776c630eefSChristoph M. Becker	if (zend_parse_parameters_none() == FAILURE) {
3786c630eefSChristoph M. Becker		return;
3796c630eefSChristoph M. Becker	}
3806c630eefSChristoph M. Becker
381baa98901SDmitry Stogov	RETURN_BOOL(gc_enabled());
38271592cecSDmitry Stogov}
38371592cecSDmitry Stogov/* }}} */
38471592cecSDmitry Stogov
38571592cecSDmitry Stogov/* {{{ proto void gc_enable(void)
38671592cecSDmitry Stogov   Activates the circular reference collector */
38771592cecSDmitry StogovZEND_FUNCTION(gc_enable)
38871592cecSDmitry Stogov{
3896c630eefSChristoph M. Becker	zend_string *key;
3906c630eefSChristoph M. Becker
3916c630eefSChristoph M. Becker	if (zend_parse_parameters_none() == FAILURE) {
3926c630eefSChristoph M. Becker		return;
3936c630eefSChristoph M. Becker	}
3946c630eefSChristoph M. Becker
3956c630eefSChristoph M. Becker	key = zend_string_init("zend.enable_gc", sizeof("zend.enable_gc")-1, 0);
39688d7ca44SDmitry Stogov	zend_alter_ini_entry_chars(key, "1", sizeof("1")-1, ZEND_INI_USER, ZEND_INI_STAGE_RUNTIME);
3975eb1f92fSDmitry Stogov	zend_string_release_ex(key, 0);
39871592cecSDmitry Stogov}
39971592cecSDmitry Stogov/* }}} */
40071592cecSDmitry Stogov
40171592cecSDmitry Stogov/* {{{ proto void gc_disable(void)
40271592cecSDmitry Stogov   Deactivates the circular reference collector */
40371592cecSDmitry StogovZEND_FUNCTION(gc_disable)
40471592cecSDmitry Stogov{
4056c630eefSChristoph M. Becker	zend_string *key;
4066c630eefSChristoph M. Becker
4076c630eefSChristoph M. Becker	if (zend_parse_parameters_none() == FAILURE) {
4086c630eefSChristoph M. Becker		return;
4096c630eefSChristoph M. Becker	}
4106c630eefSChristoph M. Becker
4116c630eefSChristoph M. Becker	key = zend_string_init("zend.enable_gc", sizeof("zend.enable_gc")-1, 0);
41288d7ca44SDmitry Stogov	zend_alter_ini_entry_chars(key, "0", sizeof("0")-1, ZEND_INI_USER, ZEND_INI_STAGE_RUNTIME);
4135eb1f92fSDmitry Stogov	zend_string_release_ex(key, 0);
41471592cecSDmitry Stogov}
41571592cecSDmitry Stogov/* }}} */
4167a4a5944SZeev Suraski
4172afc8373SDmitry Stogov/* {{{ proto array gc_status(void)
4182afc8373SDmitry Stogov   Returns current GC statistics */
4192afc8373SDmitry StogovZEND_FUNCTION(gc_status)
4202afc8373SDmitry Stogov{
4212afc8373SDmitry Stogov	zend_gc_status status;
4222afc8373SDmitry Stogov
4236c630eefSChristoph M. Becker	if (zend_parse_parameters_none() == FAILURE) {
4246c630eefSChristoph M. Becker		return;
4256c630eefSChristoph M. Becker	}
4266c630eefSChristoph M. Becker
4272afc8373SDmitry Stogov	zend_gc_get_status(&status);
4282afc8373SDmitry Stogov
4292afc8373SDmitry Stogov	array_init_size(return_value, 3);
4302afc8373SDmitry Stogov
431e788e826SDmitry Stogov	add_assoc_long_ex(return_value, "runs", sizeof("runs")-1, (long)status.runs);
4322afc8373SDmitry Stogov	add_assoc_long_ex(return_value, "collected", sizeof("collected")-1, (long)status.collected);
433e788e826SDmitry Stogov	add_assoc_long_ex(return_value, "threshold", sizeof("threshold")-1, (long)status.threshold);
4349465ec46SXinchen Hui	add_assoc_long_ex(return_value, "roots", sizeof("roots")-1, (long)status.num_roots);
4352afc8373SDmitry Stogov}
4369465ec46SXinchen Hui/* }}} */
4372afc8373SDmitry Stogov
43854767061SAndi Gutmans/* {{{ proto int func_num_args(void)
43954767061SAndi Gutmans   Get the number of arguments that were passed to the function */
440a30f028aSZeev SuraskiZEND_FUNCTION(func_num_args)
4417a4a5944SZeev Suraski{
442bd9a2346SDmitry Stogov	zend_execute_data *ex = EX(prev_execute_data);
4437a4a5944SZeev Suraski
4446c630eefSChristoph M. Becker	if (zend_parse_parameters_none() == FAILURE) {
4456c630eefSChristoph M. Becker		return;
4466c630eefSChristoph M. Becker	}
4476c630eefSChristoph M. Becker
44891f59403SNikita Popov	if (ZEND_CALL_INFO(ex) & ZEND_CALL_CODE) {
449a30f028aSZeev Suraski		zend_error(E_WARNING, "func_num_args():  Called from the global scope - no function context");
450c3e3c98eSAnatol Belski		RETURN_LONG(-1);
4517a4a5944SZeev Suraski	}
45291f59403SNikita Popov
45391f59403SNikita Popov	if (zend_forbid_dynamic_call("func_num_args()") == FAILURE) {
45491f59403SNikita Popov		RETURN_LONG(-1);
45591f59403SNikita Popov	}
45691f59403SNikita Popov
45791f59403SNikita Popov	RETURN_LONG(ZEND_CALL_NUM_ARGS(ex));
4587a4a5944SZeev Suraski}
45954767061SAndi Gutmans/* }}} */
4607a4a5944SZeev Suraski
46154767061SAndi Gutmans/* {{{ proto mixed func_get_arg(int arg_num)
46254767061SAndi Gutmans   Get the $arg_num'th argument that was passed to the function */
463a30f028aSZeev SuraskiZEND_FUNCTION(func_get_arg)
4647a4a5944SZeev Suraski{
465c8ed0d81SAnatol Belski	uint32_t arg_count, first_extra_arg;
4667a4a5944SZeev Suraski	zval *arg;
467c3e3c98eSAnatol Belski	zend_long requested_offset;
468c6978139SDmitry Stogov	zend_execute_data *ex;
4697a4a5944SZeev Suraski
470bdeb220fSAnatol Belski	if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &requested_offset) == FAILURE) {
47158a673a9SStanislav Malyshev		return;
4727a4a5944SZeev Suraski	}
4737a4a5944SZeev Suraski
474b43ba8dfSDerick Rethans	if (requested_offset < 0) {
475b43ba8dfSDerick Rethans		zend_error(E_WARNING, "func_get_arg():  The argument number should be >= 0");
476b43ba8dfSDerick Rethans		RETURN_FALSE;
477b43ba8dfSDerick Rethans	}
478b43ba8dfSDerick Rethans
479bd9a2346SDmitry Stogov	ex = EX(prev_execute_data);
4801da14c9fSDmitry Stogov	if (ZEND_CALL_INFO(ex) & ZEND_CALL_CODE) {
481a30f028aSZeev Suraski		zend_error(E_WARNING, "func_get_arg():  Called from the global scope - no function context");
4827a4a5944SZeev Suraski		RETURN_FALSE;
4837a4a5944SZeev Suraski	}
4847a4a5944SZeev Suraski
48591f59403SNikita Popov	if (zend_forbid_dynamic_call("func_get_arg()") == FAILURE) {
48691f59403SNikita Popov		RETURN_FALSE;
48791f59403SNikita Popov	}
48891f59403SNikita Popov
48911384ba7SDmitry Stogov	arg_count = ZEND_CALL_NUM_ARGS(ex);
4900b682510SDmitry Stogov
4912578d080SDmitry Stogov	if ((zend_ulong)requested_offset >= arg_count) {
4924d997f63SAnatol Belski		zend_error(E_WARNING, "func_get_arg():  Argument " ZEND_LONG_FMT " not passed to function", requested_offset);
4937a4a5944SZeev Suraski		RETURN_FALSE;
4947a4a5944SZeev Suraski	}
4957a4a5944SZeev Suraski
4963f0ee308SDmitry Stogov	first_extra_arg = ex->func->op_array.num_args;
4972578d080SDmitry Stogov	if ((zend_ulong)requested_offset >= first_extra_arg && (ZEND_CALL_NUM_ARGS(ex) > first_extra_arg)) {
498dcfe5877SDmitry Stogov		arg = ZEND_CALL_VAR_NUM(ex, ex->func->op_array.last_var + ex->func->op_array.T) + (requested_offset - first_extra_arg);
499c6978139SDmitry Stogov	} else {
500c6978139SDmitry Stogov		arg = ZEND_CALL_ARG(ex, requested_offset + 1);
501c6978139SDmitry Stogov	}
502a9636ff5SXinchen Hui	if (EXPECTED(!Z_ISUNDEF_P(arg))) {
50367b4c337SDmitry Stogov		ZVAL_COPY_DEREF(return_value, arg);
504a9636ff5SXinchen Hui	}
5057a4a5944SZeev Suraski}
50654767061SAndi Gutmans/* }}} */
5077a4a5944SZeev Suraski
50854767061SAndi Gutmans/* {{{ proto array func_get_args()
50954767061SAndi Gutmans   Get an array of the arguments that were passed to the function */
510a30f028aSZeev SuraskiZEND_FUNCTION(func_get_args)
511a30f028aSZeev Suraski{
512106b1017SDmitry Stogov	zval *p, *q;
513c8ed0d81SAnatol Belski	uint32_t arg_count, first_extra_arg;
514de66e80dSNikita Popov	uint32_t i;
515bd9a2346SDmitry Stogov	zend_execute_data *ex = EX(prev_execute_data);
516a30f028aSZeev Suraski
5171da14c9fSDmitry Stogov	if (ZEND_CALL_INFO(ex) & ZEND_CALL_CODE) {
518a30f028aSZeev Suraski		zend_error(E_WARNING, "func_get_args():  Called from the global scope - no function context");
519a30f028aSZeev Suraski		RETURN_FALSE;
520a30f028aSZeev Suraski	}
521a30f028aSZeev Suraski
52291f59403SNikita Popov	if (zend_forbid_dynamic_call("func_get_args()") == FAILURE) {
52391f59403SNikita Popov		RETURN_FALSE;
52491f59403SNikita Popov	}
52591f59403SNikita Popov
52611384ba7SDmitry Stogov	arg_count = ZEND_CALL_NUM_ARGS(ex);
527a30f028aSZeev Suraski
52822f6cf91SDmitry Stogov	if (arg_count) {
5299cf87aa1SDmitry Stogov		array_init_size(return_value, arg_count);
5303f0ee308SDmitry Stogov		first_extra_arg = ex->func->op_array.num_args;
531a795bd82SDmitry Stogov		zend_hash_real_init_packed(Z_ARRVAL_P(return_value));
532106b1017SDmitry Stogov		ZEND_HASH_FILL_PACKED(Z_ARRVAL_P(return_value)) {
533106b1017SDmitry Stogov			i = 0;
534106b1017SDmitry Stogov			p = ZEND_CALL_ARG(ex, 1);
5358dc3c283SDmitry Stogov			if (arg_count > first_extra_arg) {
536106b1017SDmitry Stogov				while (i < first_extra_arg) {
537106b1017SDmitry Stogov					q = p;
5380f3ab1c2SXinchen Hui					if (EXPECTED(Z_TYPE_INFO_P(q) != IS_UNDEF)) {
5390f3ab1c2SXinchen Hui						ZVAL_DEREF(q);
54064002648SGabriel Caruso						if (Z_OPT_REFCOUNTED_P(q)) {
5410f3ab1c2SXinchen Hui							Z_ADDREF_P(q);
5420f3ab1c2SXinchen Hui						}
543de66e80dSNikita Popov					} else {
544de66e80dSNikita Popov						q = &EG(uninitialized_zval);
5450f3ab1c2SXinchen Hui					}
546a9636ff5SXinchen Hui					ZEND_HASH_FILL_ADD(q);
547106b1017SDmitry Stogov					p++;
548106b1017SDmitry Stogov					i++;
549106b1017SDmitry Stogov				}
550106b1017SDmitry Stogov				p = ZEND_CALL_VAR_NUM(ex, ex->func->op_array.last_var + ex->func->op_array.T);
551106b1017SDmitry Stogov			}
552106b1017SDmitry Stogov			while (i < arg_count) {
553106b1017SDmitry Stogov				q = p;
5540f3ab1c2SXinchen Hui				if (EXPECTED(Z_TYPE_INFO_P(q) != IS_UNDEF)) {
5550f3ab1c2SXinchen Hui					ZVAL_DEREF(q);
55664002648SGabriel Caruso					if (Z_OPT_REFCOUNTED_P(q)) {
5570f3ab1c2SXinchen Hui						Z_ADDREF_P(q);
5580f3ab1c2SXinchen Hui					}
559de66e80dSNikita Popov				} else {
560de66e80dSNikita Popov					q = &EG(uninitialized_zval);
5610f3ab1c2SXinchen Hui				}
562a9636ff5SXinchen Hui				ZEND_HASH_FILL_ADD(q);
563c6978139SDmitry Stogov				p++;
564c6978139SDmitry Stogov				i++;
565c6978139SDmitry Stogov			}
566106b1017SDmitry Stogov		} ZEND_HASH_FILL_END();
567de66e80dSNikita Popov		Z_ARRVAL_P(return_value)->nNumOfElements = arg_count;
5689cf87aa1SDmitry Stogov	} else {
5699cf87aa1SDmitry Stogov		ZVAL_EMPTY_ARRAY(return_value);
570a30f028aSZeev Suraski	}
571a30f028aSZeev Suraski}
57254767061SAndi Gutmans/* }}} */
573a30f028aSZeev Suraski
57406a18f16SAndi Gutmans/* {{{ proto int strlen(string str)
575389d2859SAndrea Faulds   Get string length
576389d2859SAndrea Faulds   Warning: This function is special-cased by zend_compile.c and so is usually bypassed */
57734742e3fSFelipe PenaZEND_FUNCTION(strlen)
57806a18f16SAndi Gutmans{
579075a6cedSXinchen Hui	zend_string *s;
580637a4042SMarcus Boerger
58127f38798SDmitry Stogov	ZEND_PARSE_PARAMETERS_START(1, 1)
58227f38798SDmitry Stogov		Z_PARAM_STR(s)
58327f38798SDmitry Stogov	ZEND_PARSE_PARAMETERS_END();
58458a673a9SStanislav Malyshev
5857aa76271SDmitry Stogov	RETVAL_LONG(ZSTR_LEN(s));
58606a18f16SAndi Gutmans}
58706a18f16SAndi Gutmans/* }}} */
58806a18f16SAndi Gutmans
58906a18f16SAndi Gutmans/* {{{ proto int strcmp(string str1, string str2)
59006a18f16SAndi Gutmans   Binary safe string comparison */
59106a18f16SAndi GutmansZEND_FUNCTION(strcmp)
59206a18f16SAndi Gutmans{
5938ee2a4a9SAnatol Belski	zend_string *s1, *s2;
594b7a7b1a6SStanislav Malyshev
5957cce220bSRichard Fussenegger	ZEND_PARSE_PARAMETERS_START(2, 2)
5967cce220bSRichard Fussenegger		Z_PARAM_STR(s1)
5977cce220bSRichard Fussenegger		Z_PARAM_STR(s2)
5987cce220bSRichard Fussenegger	ZEND_PARSE_PARAMETERS_END();
59958a673a9SStanislav Malyshev
6007aa76271SDmitry Stogov	RETURN_LONG(zend_binary_strcmp(ZSTR_VAL(s1), ZSTR_LEN(s1), ZSTR_VAL(s2), ZSTR_LEN(s2)));
60106a18f16SAndi Gutmans}
60206a18f16SAndi Gutmans/* }}} */
60306a18f16SAndi Gutmans
604c2fd6752SAndrei Zmievski/* {{{ proto int strncmp(string str1, string str2, int len)
605c2fd6752SAndrei Zmievski   Binary safe string comparison */
606c2fd6752SAndrei ZmievskiZEND_FUNCTION(strncmp)
607c2fd6752SAndrei Zmievski{
6088ee2a4a9SAnatol Belski	zend_string *s1, *s2;
609c3e3c98eSAnatol Belski	zend_long len;
61058a673a9SStanislav Malyshev
6117cce220bSRichard Fussenegger	ZEND_PARSE_PARAMETERS_START(3, 3)
6127cce220bSRichard Fussenegger		Z_PARAM_STR(s1)
6137cce220bSRichard Fussenegger		Z_PARAM_STR(s2)
6147cce220bSRichard Fussenegger		Z_PARAM_LONG(len)
6157cce220bSRichard Fussenegger	ZEND_PARSE_PARAMETERS_END();
616e25a1dccSAntony Dovgal
61758a673a9SStanislav Malyshev	if (len < 0) {
618e25a1dccSAntony Dovgal		zend_error(E_WARNING, "Length must be greater than or equal to 0");
619e25a1dccSAntony Dovgal		RETURN_FALSE;
620e25a1dccSAntony Dovgal	}
62158a673a9SStanislav Malyshev
6227aa76271SDmitry Stogov	RETURN_LONG(zend_binary_strncmp(ZSTR_VAL(s1), ZSTR_LEN(s1), ZSTR_VAL(s2), ZSTR_LEN(s2), len));
623c2fd6752SAndrei Zmievski}
624c2fd6752SAndrei Zmievski/* }}} */
625c2fd6752SAndrei Zmievski
62606a18f16SAndi Gutmans/* {{{ proto int strcasecmp(string str1, string str2)
62706a18f16SAndi Gutmans   Binary safe case-insensitive string comparison */
62806a18f16SAndi GutmansZEND_FUNCTION(strcasecmp)
62906a18f16SAndi Gutmans{
6308ee2a4a9SAnatol Belski	zend_string *s1, *s2;
631b7a7b1a6SStanislav Malyshev
6327cce220bSRichard Fussenegger	ZEND_PARSE_PARAMETERS_START(2, 2)
6337cce220bSRichard Fussenegger		Z_PARAM_STR(s1)
6347cce220bSRichard Fussenegger		Z_PARAM_STR(s2)
6357cce220bSRichard Fussenegger	ZEND_PARSE_PARAMETERS_END();
63658a673a9SStanislav Malyshev
6377aa76271SDmitry Stogov	RETURN_LONG(zend_binary_strcasecmp(ZSTR_VAL(s1), ZSTR_LEN(s1), ZSTR_VAL(s2), ZSTR_LEN(s2)));
63806a18f16SAndi Gutmans}
63906a18f16SAndi Gutmans/* }}} */
64006a18f16SAndi Gutmans
6411373a162SStanislav Malyshev/* {{{ proto int strncasecmp(string str1, string str2, int len)
6421373a162SStanislav Malyshev   Binary safe string comparison */
6431373a162SStanislav MalyshevZEND_FUNCTION(strncasecmp)
6441373a162SStanislav Malyshev{
6458ee2a4a9SAnatol Belski	zend_string *s1, *s2;
646c3e3c98eSAnatol Belski	zend_long len;
64758a673a9SStanislav Malyshev
6487cce220bSRichard Fussenegger	ZEND_PARSE_PARAMETERS_START(3, 3)
6497cce220bSRichard Fussenegger		Z_PARAM_STR(s1)
6507cce220bSRichard Fussenegger		Z_PARAM_STR(s2)
6517cce220bSRichard Fussenegger		Z_PARAM_LONG(len)
6527cce220bSRichard Fussenegger	ZEND_PARSE_PARAMETERS_END();
653e25a1dccSAntony Dovgal
65458a673a9SStanislav Malyshev	if (len < 0) {
655e25a1dccSAntony Dovgal		zend_error(E_WARNING, "Length must be greater than or equal to 0");
656e25a1dccSAntony Dovgal		RETURN_FALSE;
657e25a1dccSAntony Dovgal	}
658e25a1dccSAntony Dovgal
6597aa76271SDmitry Stogov	RETURN_LONG(zend_binary_strncasecmp(ZSTR_VAL(s1), ZSTR_LEN(s1), ZSTR_VAL(s2), ZSTR_LEN(s2), len));
6601373a162SStanislav Malyshev}
6611373a162SStanislav Malyshev/* }}} */
6621373a162SStanislav Malyshev
663f4d08d8eSRasmus Lerdorf/* {{{ proto mixed each(array &arr)
664f4d08d8eSRasmus Lerdorf   Return the currently pointed key..value pair in the passed array, and advance the pointer to the next element, or false if there is no element at this place */
66506a18f16SAndi GutmansZEND_FUNCTION(each)
66606a18f16SAndi Gutmans{
667f4cfaf36SDmitry Stogov	zval *array, *entry, tmp;
668c3e3c98eSAnatol Belski	zend_ulong num_key;
66906a18f16SAndi Gutmans	HashTable *target_hash;
670f4cfaf36SDmitry Stogov	zend_string *key;
671637a4042SMarcus Boerger
672bdeb220fSAnatol Belski	if (zend_parse_parameters(ZEND_NUM_ARGS(), "z/", &array) == FAILURE) {
67358a673a9SStanislav Malyshev		return;
67406a18f16SAndi Gutmans	}
675896eec1eSAndi Gutmans
67606a03401SNikita Popov	if (!EG(each_deprecation_thrown)) {
67706a03401SNikita Popov		zend_error(E_DEPRECATED, "The each() function is deprecated. This message will be suppressed on further calls");
67806a03401SNikita Popov		EG(each_deprecation_thrown) = 1;
67906a03401SNikita Popov	}
68006a03401SNikita Popov
68158a673a9SStanislav Malyshev	target_hash = HASH_OF(array);
68206a18f16SAndi Gutmans	if (!target_hash) {
68306a18f16SAndi Gutmans		zend_error(E_WARNING,"Variable passed to each() is not an array or object");
68406a18f16SAndi Gutmans		return;
68506a18f16SAndi Gutmans	}
686887189caSDmitry Stogov	while (1) {
687887189caSDmitry Stogov		entry = zend_hash_get_current_data(target_hash);
688887189caSDmitry Stogov		if (!entry) {
689887189caSDmitry Stogov			RETURN_FALSE;
690887189caSDmitry Stogov		} else if (Z_TYPE_P(entry) == IS_INDIRECT) {
691887189caSDmitry Stogov			entry = Z_INDIRECT_P(entry);
692887189caSDmitry Stogov			if (Z_TYPE_P(entry) == IS_UNDEF) {
693887189caSDmitry Stogov				zend_hash_move_forward(target_hash);
694887189caSDmitry Stogov				continue;
695887189caSDmitry Stogov			}
696887189caSDmitry Stogov		}
697887189caSDmitry Stogov		break;
69806a18f16SAndi Gutmans	}
699e34a6e92SDmitry Stogov	array_init_size(return_value, 4);
700a795bd82SDmitry Stogov	zend_hash_real_init_mixed(Z_ARRVAL_P(return_value));
70106a18f16SAndi Gutmans
70206a18f16SAndi Gutmans	/* add value elements */
7037b16205fSNikita Popov	ZVAL_DEREF(entry);
704a8a17a72SXinchen Hui	if (Z_REFCOUNTED_P(entry)) {
705a8a17a72SXinchen Hui		GC_ADDREF_EX(Z_COUNTED_P(entry), 2);
706a8a17a72SXinchen Hui	}
707e34a6e92SDmitry Stogov	zend_hash_index_add_new(Z_ARRVAL_P(return_value), 1, entry);
708c6982995SAnatol Belski	zend_hash_add_new(Z_ARRVAL_P(return_value), ZSTR_KNOWN(ZEND_STR_VALUE), entry);
70906a18f16SAndi Gutmans
71006a18f16SAndi Gutmans	/* add the key elements */
7112d212b42SNikita Popov	if (zend_hash_get_current_key(target_hash, &key, &num_key) == HASH_KEY_IS_STRING) {
712bccc6531SDmitry Stogov		ZVAL_STR_COPY(&tmp, key);
713a8a17a72SXinchen Hui		Z_TRY_ADDREF(tmp);
7145864ce8aSDmitry Stogov	} else {
715c3e3c98eSAnatol Belski		ZVAL_LONG(&tmp, num_key);
71606a18f16SAndi Gutmans	}
717e34a6e92SDmitry Stogov	zend_hash_index_add_new(Z_ARRVAL_P(return_value), 0, &tmp);
718c6982995SAnatol Belski	zend_hash_add_new(Z_ARRVAL_P(return_value), ZSTR_KNOWN(ZEND_STR_KEY), &tmp);
71906a18f16SAndi Gutmans	zend_hash_move_forward(target_hash);
72006a18f16SAndi Gutmans}
72154767061SAndi Gutmans/* }}} */
72254767061SAndi Gutmans
7237cfc6b91SHannes Magnusson/* {{{ proto int error_reporting([int new_error_level])
72454767061SAndi Gutmans   Return the current error_reporting level, and if an argument was passed - change to the new level */
72506a18f16SAndi GutmansZEND_FUNCTION(error_reporting)
72606a18f16SAndi Gutmans{
7270cfb4765SDmitry Stogov	zval *err = NULL;
72806a18f16SAndi Gutmans	int old_error_reporting;
72906a18f16SAndi Gutmans
730c5047d1fSDmitry Stogov	ZEND_PARSE_PARAMETERS_START(0, 1)
731c5047d1fSDmitry Stogov		Z_PARAM_OPTIONAL
732441d1b8eSXinchen Hui		Z_PARAM_ZVAL(err)
733c5047d1fSDmitry Stogov	ZEND_PARSE_PARAMETERS_END();
73458a673a9SStanislav Malyshev
73506a18f16SAndi Gutmans	old_error_reporting = EG(error_reporting);
73691918621SXinchen Hui	if (ZEND_NUM_ARGS() != 0) {
737441d1b8eSXinchen Hui		zend_string *new_val = zval_get_string(err);
738916d5eceSDmitry Stogov		do {
739d810cf81SDmitry Stogov			zend_ini_entry *p = EG(error_reporting_ini_entry);
740d810cf81SDmitry Stogov
741d810cf81SDmitry Stogov			if (!p) {
742cc12acefSDmitry Stogov				zval *zv = zend_hash_find_ex(EG(ini_directives), ZSTR_KNOWN(ZEND_STR_ERROR_REPORTING), 1);
743cc12acefSDmitry Stogov				if (zv) {
744cc12acefSDmitry Stogov					p = EG(error_reporting_ini_entry) = (zend_ini_entry*)Z_PTR_P(zv);
745916d5eceSDmitry Stogov				} else {
746916d5eceSDmitry Stogov					break;
747916d5eceSDmitry Stogov				}
748916d5eceSDmitry Stogov			}
749d810cf81SDmitry Stogov			if (!p->modified) {
750916d5eceSDmitry Stogov				if (!EG(modified_ini_directives)) {
751916d5eceSDmitry Stogov					ALLOC_HASHTABLE(EG(modified_ini_directives));
752916d5eceSDmitry Stogov					zend_hash_init(EG(modified_ini_directives), 8, NULL, NULL, 0);
753916d5eceSDmitry Stogov				}
754c6982995SAnatol Belski				if (EXPECTED(zend_hash_add_ptr(EG(modified_ini_directives), ZSTR_KNOWN(ZEND_STR_ERROR_REPORTING), p) != NULL)) {
755d810cf81SDmitry Stogov					p->orig_value = p->value;
756d810cf81SDmitry Stogov					p->orig_modifiable = p->modifiable;
757d810cf81SDmitry Stogov					p->modified = 1;
758916d5eceSDmitry Stogov				}
75958efbf0aSDmitry Stogov			} else if (p->orig_value != p->value) {
7605eb1f92fSDmitry Stogov				zend_string_release_ex(p->value, 0);
761916d5eceSDmitry Stogov			}
762916d5eceSDmitry Stogov
763441d1b8eSXinchen Hui			p->value = new_val;
764441d1b8eSXinchen Hui			if (Z_TYPE_P(err) == IS_LONG) {
765441d1b8eSXinchen Hui				EG(error_reporting) = Z_LVAL_P(err);
766441d1b8eSXinchen Hui			} else {
767441d1b8eSXinchen Hui				EG(error_reporting) = atoi(ZSTR_VAL(p->value));
768441d1b8eSXinchen Hui			}
769916d5eceSDmitry Stogov		} while (0);
77006a18f16SAndi Gutmans	}
771fde2e61dSZeev Suraski
772c3e3c98eSAnatol Belski	RETVAL_LONG(old_error_reporting);
7737831d302SAndi Gutmans}
77454767061SAndi Gutmans/* }}} */
77554767061SAndi Gutmans
7760833fd46SDmitry Stogovstatic int validate_constant_array(HashTable *ht) /* {{{ */
7770833fd46SDmitry Stogov{
7780833fd46SDmitry Stogov	int ret = 1;
7790833fd46SDmitry Stogov	zval *val;
7800833fd46SDmitry Stogov
781cb9d81efSDmitry Stogov	GC_PROTECT_RECURSION(ht);
7820833fd46SDmitry Stogov	ZEND_HASH_FOREACH_VAL_IND(ht, val) {
7830833fd46SDmitry Stogov		ZVAL_DEREF(val);
7840833fd46SDmitry Stogov		if (Z_REFCOUNTED_P(val)) {
7850833fd46SDmitry Stogov			if (Z_TYPE_P(val) == IS_ARRAY) {
7863e9bb03aSDmitry Stogov				if (Z_REFCOUNTED_P(val)) {
787cb9d81efSDmitry Stogov					if (Z_IS_RECURSIVE_P(val)) {
7880833fd46SDmitry Stogov						zend_error(E_WARNING, "Constants cannot be recursive arrays");
7890833fd46SDmitry Stogov						ret = 0;
7900833fd46SDmitry Stogov						break;
7910833fd46SDmitry Stogov					} else if (!validate_constant_array(Z_ARRVAL_P(val))) {
7920833fd46SDmitry Stogov						ret = 0;
7930833fd46SDmitry Stogov						break;
7940833fd46SDmitry Stogov					}
7950833fd46SDmitry Stogov				}
7960833fd46SDmitry Stogov			} else if (Z_TYPE_P(val) != IS_STRING && Z_TYPE_P(val) != IS_RESOURCE) {
7970a6ddc77SMichael Moravec				zend_error(E_WARNING, "Constants may only evaluate to scalar values, arrays or resources");
7980833fd46SDmitry Stogov				ret = 0;
7990833fd46SDmitry Stogov				break;
800b7a7b1a6SStanislav Malyshev			}
8010833fd46SDmitry Stogov		}
8020833fd46SDmitry Stogov	} ZEND_HASH_FOREACH_END();
803cb9d81efSDmitry Stogov	GC_UNPROTECT_RECURSION(ht);
8040833fd46SDmitry Stogov	return ret;
8050833fd46SDmitry Stogov}
8060833fd46SDmitry Stogov/* }}} */
8070833fd46SDmitry Stogov
8080833fd46SDmitry Stogovstatic void copy_constant_array(zval *dst, zval *src) /* {{{ */
8090833fd46SDmitry Stogov{
8100833fd46SDmitry Stogov	zend_string *key;
8110833fd46SDmitry Stogov	zend_ulong idx;
8120833fd46SDmitry Stogov	zval *new_val, *val;
8130833fd46SDmitry Stogov
8140833fd46SDmitry Stogov	array_init_size(dst, zend_hash_num_elements(Z_ARRVAL_P(src)));
8150833fd46SDmitry Stogov	ZEND_HASH_FOREACH_KEY_VAL_IND(Z_ARRVAL_P(src), idx, key, val) {
8160833fd46SDmitry Stogov		/* constant arrays can't contain references */
817faf917d9SDmitry Stogov		ZVAL_DEREF(val);
8180833fd46SDmitry Stogov		if (key) {
8190833fd46SDmitry Stogov			new_val = zend_hash_add_new(Z_ARRVAL_P(dst), key, val);
8200833fd46SDmitry Stogov		} else {
8210833fd46SDmitry Stogov			new_val = zend_hash_index_add_new(Z_ARRVAL_P(dst), idx, val);
822b7a7b1a6SStanislav Malyshev		}
8230833fd46SDmitry Stogov		if (Z_TYPE_P(val) == IS_ARRAY) {
8243e9bb03aSDmitry Stogov			if (Z_REFCOUNTED_P(val)) {
8250833fd46SDmitry Stogov				copy_constant_array(new_val, val);
8260833fd46SDmitry Stogov			}
827d56a534aSXinchen Hui		} else {
828d56a534aSXinchen Hui			Z_TRY_ADDREF_P(val);
8290833fd46SDmitry Stogov		}
8300833fd46SDmitry Stogov	} ZEND_HASH_FOREACH_END();
8310833fd46SDmitry Stogov}
8320833fd46SDmitry Stogov/* }}} */
8330833fd46SDmitry Stogov
834affc20f8SGabriel Caruso/* {{{ proto bool define(string constant_name, mixed value[, bool case_insensitive])
83554767061SAndi Gutmans   Define a new constant */
83668217ef5SAndi GutmansZEND_FUNCTION(define)
83768217ef5SAndi Gutmans{
838a821009aSDmitry Stogov	zend_string *name;
839f4cfaf36SDmitry Stogov	zval *val, val_free;
84058a673a9SStanislav Malyshev	zend_bool non_cs = 0;
84158a673a9SStanislav Malyshev	int case_sensitive = CONST_CS;
84268217ef5SAndi Gutmans	zend_constant c;
843637a4042SMarcus Boerger
84427f38798SDmitry Stogov	ZEND_PARSE_PARAMETERS_START(2, 3)
84527f38798SDmitry Stogov		Z_PARAM_STR(name)
84627f38798SDmitry Stogov		Z_PARAM_ZVAL(val)
84727f38798SDmitry Stogov		Z_PARAM_OPTIONAL
84827f38798SDmitry Stogov		Z_PARAM_BOOL(non_cs)
84927f38798SDmitry Stogov	ZEND_PARSE_PARAMETERS_END();
85058a673a9SStanislav Malyshev
8516815c08eSXinchen Hui	if (non_cs) {
85258a673a9SStanislav Malyshev		case_sensitive = 0;
85368217ef5SAndi Gutmans	}
8542c95b113SStanislav Malyshev
8557aa76271SDmitry Stogov	if (zend_memnstr(ZSTR_VAL(name), "::", sizeof("::") - 1, ZSTR_VAL(name) + ZSTR_LEN(name))) {
856b63f178eSIlia Alshanetsky		zend_error(E_WARNING, "Class constants cannot be defined or redefined");
857b63f178eSIlia Alshanetsky		RETURN_FALSE;
8585289261bSIlia Alshanetsky	}
8595289261bSIlia Alshanetsky
860f4cfaf36SDmitry Stogov	ZVAL_UNDEF(&val_free);
861f4cfaf36SDmitry Stogov
862dd5cbcd2SMarcus Boergerrepeat:
86358a673a9SStanislav Malyshev	switch (Z_TYPE_P(val)) {
864c3e3c98eSAnatol Belski		case IS_LONG:
86568217ef5SAndi Gutmans		case IS_DOUBLE:
86668217ef5SAndi Gutmans		case IS_STRING:
86717d027edSDmitry Stogov		case IS_FALSE:
86817d027edSDmitry Stogov		case IS_TRUE:
869bdefd5daSAndi Gutmans		case IS_NULL:
8706815c08eSXinchen Hui		case IS_RESOURCE:
8716815c08eSXinchen Hui			break;
8720833fd46SDmitry Stogov		case IS_ARRAY:
8733e9bb03aSDmitry Stogov			if (Z_REFCOUNTED_P(val)) {
8740833fd46SDmitry Stogov				if (!validate_constant_array(Z_ARRVAL_P(val))) {
8750833fd46SDmitry Stogov					RETURN_FALSE;
8760833fd46SDmitry Stogov				} else {
8770833fd46SDmitry Stogov					copy_constant_array(&c.value, val);
8780833fd46SDmitry Stogov					goto register_constant;
8790833fd46SDmitry Stogov				}
8800833fd46SDmitry Stogov			}
8810833fd46SDmitry Stogov			break;
882dd5cbcd2SMarcus Boerger		case IS_OBJECT:
883f4cfaf36SDmitry Stogov			if (Z_TYPE(val_free) == IS_UNDEF) {
88458a673a9SStanislav Malyshev				if (Z_OBJ_HT_P(val)->get) {
8851e0bc6e3SChristoph M. Becker					val = Z_OBJ_HT_P(val)->get(val, &val_free);
886dd5cbcd2SMarcus Boerger					goto repeat;
88758a673a9SStanislav Malyshev				} else if (Z_OBJ_HT_P(val)->cast_object) {
888bdeb220fSAnatol Belski					if (Z_OBJ_HT_P(val)->cast_object(val, &val_free, IS_STRING) == SUCCESS) {
889f4cfaf36SDmitry Stogov						val = &val_free;
890dd5cbcd2SMarcus Boerger						break;
891dd5cbcd2SMarcus Boerger					}
892dd5cbcd2SMarcus Boerger				}
893dd5cbcd2SMarcus Boerger			}
894dd5cbcd2SMarcus Boerger			/* no break */
89568217ef5SAndi Gutmans		default:
8960a6ddc77SMichael Moravec			zend_error(E_WARNING, "Constants may only evaluate to scalar values, arrays or resources");
897f4cfaf36SDmitry Stogov			zval_ptr_dtor(&val_free);
89868217ef5SAndi Gutmans			RETURN_FALSE;
89968217ef5SAndi Gutmans	}
900b7a7b1a6SStanislav Malyshev
901490960d8SDmitry Stogov	ZVAL_COPY(&c.value, val);
902f4cfaf36SDmitry Stogov	zval_ptr_dtor(&val_free);
9033588d8afSNikita Popov
9040833fd46SDmitry Stogovregister_constant:
9053588d8afSNikita Popov	if (non_cs) {
9063588d8afSNikita Popov		zend_error(E_DEPRECATED,
9073588d8afSNikita Popov			"define(): Declaration of case-insensitive constants is deprecated");
9083588d8afSNikita Popov	}
9093588d8afSNikita Popov
910ab8094c6SDmitry Stogov	/* non persistent */
911ab8094c6SDmitry Stogov	ZEND_CONSTANT_SET_FLAGS(&c, case_sensitive, PHP_USER_CONSTANT);
912c3e3c98eSAnatol Belski	c.name = zend_string_copy(name);
913bdeb220fSAnatol Belski	if (zend_register_constant(&c) == SUCCESS) {
9144f77354cSDerick Rethans		RETURN_TRUE;
9152c95b113SStanislav Malyshev	} else {
9164f77354cSDerick Rethans		RETURN_FALSE;
9172c95b113SStanislav Malyshev	}
91868217ef5SAndi Gutmans}
91954767061SAndi Gutmans/* }}} */
92068217ef5SAndi Gutmans
9210c6be867SDerick Rethans/* {{{ proto bool defined(string constant_name)
922389d2859SAndrea Faulds   Check whether a constant exists
923389d2859SAndrea Faulds   Warning: This function is special-cased by zend_compile.c and so is usually bypassed */
92468217ef5SAndi GutmansZEND_FUNCTION(defined)
92568217ef5SAndi Gutmans{
926df7ca608SDmitry Stogov	zend_string *name;
927637a4042SMarcus Boerger
92827f38798SDmitry Stogov	ZEND_PARSE_PARAMETERS_START(1, 1)
92927f38798SDmitry Stogov		Z_PARAM_STR(name)
93027f38798SDmitry Stogov	ZEND_PARSE_PARAMETERS_END();
931b7a7b1a6SStanislav Malyshev
9323588d8afSNikita Popov	if (zend_get_constant_ex(name, zend_get_executed_scope(), ZEND_FETCH_CLASS_SILENT | ZEND_GET_CONSTANT_NO_DEPRECATION_CHECK)) {
933a84efbe9SDerick Rethans		RETURN_TRUE;
93468217ef5SAndi Gutmans	} else {
935a84efbe9SDerick Rethans		RETURN_FALSE;
93668217ef5SAndi Gutmans	}
93768217ef5SAndi Gutmans}
93854767061SAndi Gutmans/* }}} */
93954767061SAndi Gutmans
9404efbb350SMarcus Boerger/* {{{ proto string get_class([object object])
94168ab1d3dSEgon Schmid   Retrieves the class name */
94268217ef5SAndi GutmansZEND_FUNCTION(get_class)
94368217ef5SAndi Gutmans{
94458a673a9SStanislav Malyshev	zval *obj = NULL;
945637a4042SMarcus Boerger
94686aa1c78SDanack	if (zend_parse_parameters(ZEND_NUM_ARGS(), "|o", &obj) == FAILURE) {
947cc91da1bSDmitry Stogov		RETURN_FALSE;
94858a673a9SStanislav Malyshev	}
94958a673a9SStanislav Malyshev
95058a673a9SStanislav Malyshev	if (!obj) {
9516499162fSDmitry Stogov		zend_class_entry *scope = zend_get_executed_scope();
9526499162fSDmitry Stogov
9536499162fSDmitry Stogov		if (scope) {
9546499162fSDmitry Stogov			RETURN_STR_COPY(scope->name);
9554efbb350SMarcus Boerger		} else {
956badf27fbSAntony Dovgal			zend_error(E_WARNING, "get_class() called without object from outside a class");
957badf27fbSAntony Dovgal			RETURN_FALSE;
9584efbb350SMarcus Boerger		}
9594efbb350SMarcus Boerger	}
960896eec1eSAndi Gutmans
96186336856SDmitry Stogov	RETURN_STR_COPY(Z_OBJCE_P(obj)->name);
96268217ef5SAndi Gutmans}
96368217ef5SAndi Gutmans/* }}} */
96468217ef5SAndi Gutmans
965166266dfSDmitry Stogov/* {{{ proto string get_called_class()
966166266dfSDmitry Stogov   Retrieves the "Late Static Binding" class name */
967166266dfSDmitry StogovZEND_FUNCTION(get_called_class)
968166266dfSDmitry Stogov{
96949cf7c5dSDmitry Stogov	zend_class_entry *called_scope;
97049cf7c5dSDmitry Stogov
97158a673a9SStanislav Malyshev	if (zend_parse_parameters_none() == FAILURE) {
97258a673a9SStanislav Malyshev		return;
97358a673a9SStanislav Malyshev	}
97458a673a9SStanislav Malyshev
97549cf7c5dSDmitry Stogov	called_scope = zend_get_called_scope(execute_data);
97649cf7c5dSDmitry Stogov	if (called_scope) {
97749cf7c5dSDmitry Stogov		RETURN_STR_COPY(called_scope->name);
9786499162fSDmitry Stogov	} else {
9796499162fSDmitry Stogov		zend_class_entry *scope = zend_get_executed_scope();
9806499162fSDmitry Stogov		if (!scope)  {
9816499162fSDmitry Stogov			zend_error(E_WARNING, "get_called_class() called from outside a class");
9826499162fSDmitry Stogov		}
983166266dfSDmitry Stogov	}
98423f7fa57SFelipe Pena	RETURN_FALSE;
985166266dfSDmitry Stogov}
986166266dfSDmitry Stogov/* }}} */
987166266dfSDmitry Stogov
988f4d08d8eSRasmus Lerdorf/* {{{ proto mixed get_parent_class([mixed object])
989f4d08d8eSRasmus Lerdorf   Retrieves the parent class name for object or class or current scope or false if not in a scope. */
99068217ef5SAndi GutmansZEND_FUNCTION(get_parent_class)
99168217ef5SAndi Gutmans{
99258a673a9SStanislav Malyshev	zval *arg;
99354da9024SAndrei Zmievski	zend_class_entry *ce = NULL;
994b7a7b1a6SStanislav Malyshev
995bdeb220fSAnatol Belski	if (zend_parse_parameters(ZEND_NUM_ARGS(), "|z", &arg) == FAILURE) {
99658a673a9SStanislav Malyshev		return;
99758a673a9SStanislav Malyshev	}
99858a673a9SStanislav Malyshev
999b52ab41cSMarcus Boerger	if (!ZEND_NUM_ARGS()) {
10006499162fSDmitry Stogov		ce = zend_get_executed_scope();
1001b52ab41cSMarcus Boerger		if (ce && ce->parent) {
100286336856SDmitry Stogov			RETURN_STR_COPY(ce->parent->name);
1003b52ab41cSMarcus Boerger		} else {
1004b52ab41cSMarcus Boerger			RETURN_FALSE;
1005b52ab41cSMarcus Boerger		}
1006b52ab41cSMarcus Boerger	}
100754da9024SAndrei Zmievski
100858a673a9SStanislav Malyshev	if (Z_TYPE_P(arg) == IS_OBJECT) {
1009df79b9b2SNikita Popov		ce = Z_OBJ_P(arg)->ce;
101058a673a9SStanislav Malyshev	} else if (Z_TYPE_P(arg) == IS_STRING) {
1011bdeb220fSAnatol Belski	    ce = zend_lookup_class(Z_STR_P(arg));
101254da9024SAndrei Zmievski	}
101354da9024SAndrei Zmievski
101454da9024SAndrei Zmievski	if (ce && ce->parent) {
101586336856SDmitry Stogov		RETURN_STR_COPY(ce->parent->name);
101654da9024SAndrei Zmievski	} else {
101768217ef5SAndi Gutmans		RETURN_FALSE;
101868217ef5SAndi Gutmans	}
101968217ef5SAndi Gutmans}
102068217ef5SAndi Gutmans/* }}} */
1021c9c6446aSAndrei Zmievski
10227ecc7e6bSXinchen Huistatic void is_a_impl(INTERNAL_FUNCTION_PARAMETERS, zend_bool only_subclass) /* {{{ */
1023c9c6446aSAndrei Zmievski{
102458a673a9SStanislav Malyshev	zval *obj;
1025f4cfaf36SDmitry Stogov	zend_string *class_name;
102626dd8492SZeev Suraski	zend_class_entry *instance_ce;
1027f4cfaf36SDmitry Stogov	zend_class_entry *ce;
10283598185aSStanislav Malyshev	zend_bool allow_string = only_subclass;
102926dd8492SZeev Suraski	zend_bool retval;
1030c9c6446aSAndrei Zmievski
103127f38798SDmitry Stogov	ZEND_PARSE_PARAMETERS_START(2, 3)
103227f38798SDmitry Stogov		Z_PARAM_ZVAL(obj)
103327f38798SDmitry Stogov		Z_PARAM_STR(class_name)
103427f38798SDmitry Stogov		Z_PARAM_OPTIONAL
103527f38798SDmitry Stogov		Z_PARAM_BOOL(allow_string)
103627f38798SDmitry Stogov	ZEND_PARSE_PARAMETERS_END();
10373598185aSStanislav Malyshev	/*
1038b7a7b1a6SStanislav Malyshev	 * allow_string - is_a default is no, is_subclass_of is yes.
10393598185aSStanislav Malyshev	 *   if it's allowed, then the autoloader will be called if the class does not exist.
10403598185aSStanislav Malyshev	 *   default behaviour is different, as 'is_a' used to be used to test mixed return values
10413598185aSStanislav Malyshev	 *   and there is no easy way to deprecate this.
10423598185aSStanislav Malyshev	 */
10433598185aSStanislav Malyshev
10443598185aSStanislav Malyshev	if (allow_string && Z_TYPE_P(obj) == IS_STRING) {
1045bdeb220fSAnatol Belski		instance_ce = zend_lookup_class(Z_STR_P(obj));
1046f4cfaf36SDmitry Stogov		if (!instance_ce) {
10476a16f3ebSAndi Gutmans			RETURN_FALSE;
10486a16f3ebSAndi Gutmans		}
1049ee5b30faSNikita Popov	} else if (Z_TYPE_P(obj) == IS_OBJECT) {
1050adabdedeSDmitry Stogov		instance_ce = Z_OBJCE_P(obj);
10516a16f3ebSAndi Gutmans	} else {
10526608f073SStanislav Malyshev		RETURN_FALSE;
10536608f073SStanislav Malyshev	}
1054c9c6446aSAndrei Zmievski
1055442efdaaSXinchen Hui	if (!only_subclass && EXPECTED(zend_string_equals(instance_ce->name, class_name))) {
1056442efdaaSXinchen Hui		retval = 1;
105726dd8492SZeev Suraski	} else {
1058442efdaaSXinchen Hui		ce = zend_lookup_class_ex(class_name, NULL, 0);
1059442efdaaSXinchen Hui		if (!ce) {
106026dd8492SZeev Suraski			retval = 0;
1061442efdaaSXinchen Hui		} else {
1062442efdaaSXinchen Hui			if (only_subclass && instance_ce == ce) {
1063442efdaaSXinchen Hui				retval = 0;
1064442efdaaSXinchen Hui			} else {
1065442efdaaSXinchen Hui				retval = instanceof_function(instance_ce, ce);
1066442efdaaSXinchen Hui			}
1067c9c6446aSAndrei Zmievski		}
10688a879b8fSAndrei Zmievski	}
106926dd8492SZeev Suraski
107026dd8492SZeev Suraski	RETURN_BOOL(retval);
1071c9c6446aSAndrei Zmievski}
10727ecc7e6bSXinchen Hui/* }}} */
1073031784c6SSebastian Bergmann
1074f4d08d8eSRasmus Lerdorf/* {{{ proto bool is_subclass_of(mixed object_or_string, string class_name [, bool allow_string])
10757f52928eSfoobar   Returns true if the object has this class as one of its parents */
1076031784c6SSebastian BergmannZEND_FUNCTION(is_subclass_of)
1077031784c6SSebastian Bergmann{
1078031784c6SSebastian Bergmann	is_a_impl(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1);
1079031784c6SSebastian Bergmann}
1080031784c6SSebastian Bergmann/* }}} */
1081031784c6SSebastian Bergmann
1082f4d08d8eSRasmus Lerdorf/* {{{ proto bool is_a(mixed object_or_string, string class_name [, bool allow_string])
10833598185aSStanislav Malyshev   Returns true if the first argument is an object and is this class or has this class as one of its parents, */
1084031784c6SSebastian BergmannZEND_FUNCTION(is_a)
1085031784c6SSebastian Bergmann{
1086031784c6SSebastian Bergmann	is_a_impl(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0);
1087031784c6SSebastian Bergmann}
1088c9c6446aSAndrei Zmievski/* }}} */
108968217ef5SAndi Gutmans
10900c40e2a0SMarcus Boerger/* {{{ add_class_vars */
10916499162fSDmitry Stogovstatic void add_class_vars(zend_class_entry *scope, zend_class_entry *ce, int statics, zval *return_value)
10920c40e2a0SMarcus Boerger{
1093c5237d82SDmitry Stogov	zend_property_info *prop_info;
1094f4cfaf36SDmitry Stogov	zval *prop, prop_copy;
1095f4cfaf36SDmitry Stogov	zend_string *key;
1096c5237d82SDmitry Stogov
10975864ce8aSDmitry Stogov	ZEND_HASH_FOREACH_STR_KEY_PTR(&ce->properties_info, key, prop_info) {
1098c5237d82SDmitry Stogov		if (((prop_info->flags & ZEND_ACC_SHADOW) &&
10996499162fSDmitry Stogov		     prop_info->ce != scope) ||
1100c5237d82SDmitry Stogov		    ((prop_info->flags & ZEND_ACC_PROTECTED) &&
11016499162fSDmitry Stogov		     !zend_check_protected(prop_info->ce, scope)) ||
1102c5237d82SDmitry Stogov		    ((prop_info->flags & ZEND_ACC_PRIVATE) &&
11036499162fSDmitry Stogov		      ce != scope &&
11046499162fSDmitry Stogov			  prop_info->ce != scope)) {
1105c5237d82SDmitry Stogov			continue;
1106c5237d82SDmitry Stogov		}
1107c5237d82SDmitry Stogov		prop = NULL;
110875041379SDmitry Stogov		if (statics && (prop_info->flags & ZEND_ACC_STATIC) != 0) {
110975041379SDmitry Stogov			prop = &ce->default_static_members_table[prop_info->offset];
11102543e61aSNikita Popov			ZVAL_DEINDIRECT(prop);
111175041379SDmitry Stogov		} else if (!statics && (prop_info->flags & ZEND_ACC_STATIC) == 0) {
111275041379SDmitry Stogov			prop = &ce->default_properties_table[OBJ_PROP_TO_NUM(prop_info->offset)];
1113c5237d82SDmitry Stogov		}
1114f4cfaf36SDmitry Stogov		if (!prop || Z_TYPE_P(prop) == IS_UNDEF) {
1115c5237d82SDmitry Stogov			continue;
1116c5237d82SDmitry Stogov		}
11170c40e2a0SMarcus Boerger
1118c5237d82SDmitry Stogov		/* copy: enforce read only access */
11190427ae08SDmitry Stogov		ZVAL_DEREF(prop);
1120fcc08ce1SDmitry Stogov		ZVAL_COPY_OR_DUP(&prop_copy, prop);
1121fcc08ce1SDmitry Stogov		prop = &prop_copy;
1122637a4042SMarcus Boerger
1123c5237d82SDmitry Stogov		/* this is necessary to make it able to work with default array
1124c5237d82SDmitry Stogov		 * properties, returned to user */
1125ef5ea487SDmitry Stogov		if (Z_OPT_TYPE_P(prop) == IS_CONSTANT_AST) {
11266499162fSDmitry Stogov			if (UNEXPECTED(zval_update_constant_ex(prop, NULL) != SUCCESS)) {
1127ea09a9faSDmitry Stogov				return;
1128ea09a9faSDmitry Stogov			}
11290c40e2a0SMarcus Boerger		}
1130c5237d82SDmitry Stogov
11310427ae08SDmitry Stogov		zend_hash_add_new(Z_ARRVAL_P(return_value), key, prop);
11327652a977SDmitry Stogov	} ZEND_HASH_FOREACH_END();
11330c40e2a0SMarcus Boerger}
11340c40e2a0SMarcus Boerger/* }}} */
11350c40e2a0SMarcus Boerger
1136685fd429SAndrei Zmievski/* {{{ proto array get_class_vars(string class_name)
11370c40e2a0SMarcus Boerger   Returns an array of default properties of the class. */
1138685fd429SAndrei ZmievskiZEND_FUNCTION(get_class_vars)
1139685fd429SAndrei Zmievski{
1140f4cfaf36SDmitry Stogov	zend_string *class_name;
11416499162fSDmitry Stogov	zend_class_entry *ce, *scope;
1142685fd429SAndrei Zmievski
1143bdeb220fSAnatol Belski	if (zend_parse_parameters(ZEND_NUM_ARGS(), "S", &class_name) == FAILURE) {
11440c40e2a0SMarcus Boerger		return;
1145685fd429SAndrei Zmievski	}
1146685fd429SAndrei Zmievski
1147bdeb220fSAnatol Belski	ce = zend_lookup_class(class_name);
1148f4cfaf36SDmitry Stogov	if (!ce) {
1149685fd429SAndrei Zmievski		RETURN_FALSE;
1150685fd429SAndrei Zmievski	} else {
1151685fd429SAndrei Zmievski		array_init(return_value);
1152ca64b41bSDmitry Stogov		if (UNEXPECTED(!(ce->ce_flags & ZEND_ACC_CONSTANTS_UPDATED))) {
1153ca64b41bSDmitry Stogov			if (UNEXPECTED(zend_update_class_constants(ce) != SUCCESS)) {
1154ca64b41bSDmitry Stogov				return;
1155ca64b41bSDmitry Stogov			}
1156ea09a9faSDmitry Stogov		}
11576499162fSDmitry Stogov		scope = zend_get_executed_scope();
11586499162fSDmitry Stogov		add_class_vars(scope, ce, 0, return_value);
11596499162fSDmitry Stogov		add_class_vars(scope, ce, 1, return_value);
1160685fd429SAndrei Zmievski	}
1161685fd429SAndrei Zmievski}
1162685fd429SAndrei Zmievski/* }}} */
1163685fd429SAndrei Zmievski
1164685fd429SAndrei Zmievski/* {{{ proto array get_object_vars(object obj)
1165685fd429SAndrei Zmievski   Returns an array of object properties */
1166685fd429SAndrei ZmievskiZEND_FUNCTION(get_object_vars)
1167685fd429SAndrei Zmievski{
116858a673a9SStanislav Malyshev	zval *obj;
1169f4cfaf36SDmitry Stogov	zval *value;
11707cc93e12SMarcus Boerger	HashTable *properties;
1171f4cfaf36SDmitry Stogov	zend_string *key;
11727ec48cb3SDmitry Stogov	zend_object *zobj;
1173dd9ad094SNikita Popov	zend_ulong num_key;
1174685fd429SAndrei Zmievski
117527f38798SDmitry Stogov	ZEND_PARSE_PARAMETERS_START(1, 1)
117627f38798SDmitry Stogov		Z_PARAM_OBJECT(obj)
117727f38798SDmitry Stogov	ZEND_PARSE_PARAMETERS_END();
1178685fd429SAndrei Zmievski
117958a673a9SStanislav Malyshev	if (Z_OBJ_HT_P(obj)->get_properties == NULL) {
11806608f073SStanislav Malyshev		RETURN_FALSE;
11816608f073SStanislav Malyshev	}
1182685fd429SAndrei Zmievski
1183bdeb220fSAnatol Belski	properties = Z_OBJ_HT_P(obj)->get_properties(obj);
1184da307918SAndrei Zmievski
1185da307918SAndrei Zmievski	if (properties == NULL) {
1186da307918SAndrei Zmievski		RETURN_FALSE;
1187da307918SAndrei Zmievski	}
1188da307918SAndrei Zmievski
1189f4cfaf36SDmitry Stogov	zobj = Z_OBJ_P(obj);
11904b395a16SMarcus Boerger
1191cb9d81efSDmitry Stogov	if (!zobj->ce->default_properties_count && properties == zobj->properties && !GC_IS_RECURSIVE(properties)) {
1192f3506dfaSDmitry Stogov		/* fast copy */
11934a6e1345SDmitry Stogov		if (EXPECTED(