zend.c revision 7aa76271
1573b4602SAndi Gutmans/*
2573b4602SAndi Gutmans   +----------------------------------------------------------------------+
3573b4602SAndi Gutmans   | Zend Engine                                                          |
4573b4602SAndi Gutmans   +----------------------------------------------------------------------+
5fc33f52dSXinchen Hui   | Copyright (c) 1998-2015 Zend Technologies Ltd. (http://www.zend.com) |
6573b4602SAndi Gutmans   +----------------------------------------------------------------------+
7d863d52aSSebastian Bergmann   | This source file is subject to version 2.00 of the Zend license,     |
8b5b11177SZeev 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.                                |
11b5b11177SZeev Suraski   | If you did not receive a copy of the Zend license and are unable to  |
12b5b11177SZeev Suraski   | obtain it through the world-wide-web, please send a note to          |
13b5b11177SZeev Suraski   | license@zend.com so we can mail you a copy immediately.              |
14573b4602SAndi Gutmans   +----------------------------------------------------------------------+
15573b4602SAndi Gutmans   | Authors: Andi Gutmans <andi@zend.com>                                |
16573b4602SAndi Gutmans   |          Zeev Suraski <zeev@zend.com>                                |
17573b4602SAndi Gutmans   +----------------------------------------------------------------------+
18573b4602SAndi Gutmans*/
19573b4602SAndi Gutmans
20333406bdSfoobar/* $Id$ */
21a6043d3eSRasmus Lerdorf
22573b4602SAndi Gutmans#include "zend.h"
23573b4602SAndi Gutmans#include "zend_extensions.h"
247080fa5bSAndi Gutmans#include "zend_modules.h"
25573b4602SAndi Gutmans#include "zend_constants.h"
26573b4602SAndi Gutmans#include "zend_list.h"
27da9faa2cSZeev Suraski#include "zend_API.h"
2800ed3badSZeev Suraski#include "zend_exceptions.h"
2913d840bcSZeev Suraski#include "zend_builtin_functions.h"
3054d53055SZeev Suraski#include "zend_ini.h"
31fcaa1c6dSDmitry Stogov#include "zend_vm.h"
3208b9fdc8SDavid Soria Parra#include "zend_dtrace.h"
33cf6ab0e9SAnatol Belski#include "zend_virtual_cwd.h"
34573b4602SAndi Gutmans
357a87fcbbSZeev Suraski#ifdef ZTS
36b4892511SJani Taskinen# define GLOBAL_FUNCTION_TABLE		global_function_table
37b4892511SJani Taskinen# define GLOBAL_CLASS_TABLE			global_class_table
38b4892511SJani Taskinen# define GLOBAL_CONSTANTS_TABLE		global_constants_table
39b4892511SJani Taskinen# define GLOBAL_AUTO_GLOBALS_TABLE	global_auto_globals_table
407a87fcbbSZeev Suraski#else
41b4892511SJani Taskinen# define GLOBAL_FUNCTION_TABLE		CG(function_table)
42b4892511SJani Taskinen# define GLOBAL_CLASS_TABLE			CG(class_table)
43b4892511SJani Taskinen# define GLOBAL_AUTO_GLOBALS_TABLE	CG(auto_globals)
44b4892511SJani Taskinen# define GLOBAL_CONSTANTS_TABLE		EG(zend_constants)
457a87fcbbSZeev Suraski#endif
467a87fcbbSZeev Suraski
47573b4602SAndi Gutmans/* true multithread-shared globals */
4892dd5e61SStanislav MalyshevZEND_API zend_class_entry *zend_standard_class_def = NULL;
49c3e3c98eSAnatol BelskiZEND_API size_t (*zend_printf)(const char *format, ...);
505dba4774SZeev SuraskiZEND_API zend_write_func_t zend_write;
512fa8d67aSDmitry StogovZEND_API FILE *(*zend_fopen)(const char *filename, zend_string **opened_path);
52bdeb220fSAnatol BelskiZEND_API int (*zend_stream_open_function)(const char *filename, zend_file_handle *handle);
5393536507SStig S. BakkenZEND_API void (*zend_block_interruptions)(void);
5493536507SStig S. BakkenZEND_API void (*zend_unblock_interruptions)(void);
55bdeb220fSAnatol BelskiZEND_API void (*zend_ticks_function)(int ticks);
56536221beSStanislav MalyshevZEND_API void (*zend_error_cb)(int type, const char *error_filename, const uint error_lineno, const char *format, va_list args);
57c3e3c98eSAnatol Belskisize_t (*zend_vspprintf)(char **pbuf, size_t max_len, const char *format, va_list ap);
5888c550a7SXinchen Huizend_string *(*zend_vstrpprintf)(size_t max_len, const char *format, va_list ap);
59bdeb220fSAnatol BelskiZEND_API char *(*zend_getenv)(char *name, size_t name_len);
602fa8d67aSDmitry StogovZEND_API zend_string *(*zend_resolve_path)(const char *filename, int filename_len);
61536221beSStanislav Malyshev
62bdeb220fSAnatol Belskivoid (*zend_on_timeout)(int seconds);
63bd115087SZeev Suraski
64bdeb220fSAnatol Belskistatic void (*zend_message_dispatcher_p)(zend_long message, const void *data);
6588d7ca44SDmitry Stogovstatic zval *(*zend_get_configuration_directive_p)(zend_string *name);
66d035af4aSZeev Suraski
67b4892511SJani Taskinenstatic ZEND_INI_MH(OnUpdateErrorReporting) /* {{{ */
684be862b0SZeev Suraski{
694be862b0SZeev Suraski	if (!new_value) {
70d3e50265SMarcus Boerger		EG(error_reporting) = E_ALL & ~E_NOTICE & ~E_STRICT & ~E_DEPRECATED;
714be862b0SZeev Suraski	} else {
727aa76271SDmitry Stogov		EG(error_reporting) = atoi(ZSTR_VAL(new_value));
734be862b0SZeev Suraski	}
744be862b0SZeev Suraski	return SUCCESS;
754be862b0SZeev Suraski}
76b4892511SJani Taskinen/* }}} */
774be862b0SZeev Suraski
7871592cecSDmitry Stogovstatic ZEND_INI_MH(OnUpdateGCEnabled) /* {{{ */
7971592cecSDmitry Stogov{
80bdeb220fSAnatol Belski	OnUpdateBool(entry, new_value, mh_arg1, mh_arg2, mh_arg3, stage);
8171592cecSDmitry Stogov
8271592cecSDmitry Stogov	if (GC_G(gc_enabled)) {
83bdeb220fSAnatol Belski		gc_init();
8471592cecSDmitry Stogov	}
8571592cecSDmitry Stogov
8671592cecSDmitry Stogov	return SUCCESS;
8771592cecSDmitry Stogov}
8871592cecSDmitry Stogov/* }}} */
8971592cecSDmitry Stogov
90bbf3d43cSMoriyoshi Koizumistatic ZEND_INI_MH(OnUpdateScriptEncoding) /* {{{ */
91bbf3d43cSMoriyoshi Koizumi{
92e46852d2SAnatol Belski	if (!CG(multibyte)) {
93bbf3d43cSMoriyoshi Koizumi		return FAILURE;
94bbf3d43cSMoriyoshi Koizumi	}
95bdeb220fSAnatol Belski	if (!zend_multibyte_get_functions()) {
96bbf3d43cSMoriyoshi Koizumi		return SUCCESS;
97bbf3d43cSMoriyoshi Koizumi	}
987aa76271SDmitry Stogov	return zend_multibyte_set_script_encoding_by_string(new_value ? ZSTR_VAL(new_value) : NULL, new_value ? ZSTR_LEN(new_value) : 0);
99bbf3d43cSMoriyoshi Koizumi}
100bbf3d43cSMoriyoshi Koizumi/* }}} */
101bbf3d43cSMoriyoshi Koizumi
1029a20323eSDmitry Stogovstatic ZEND_INI_MH(OnUpdateAssertions) /* {{{ */
1039a20323eSDmitry Stogov{
1049a20323eSDmitry Stogov	zend_long *p, val;
1059a20323eSDmitry Stogov#ifndef ZTS
1069a20323eSDmitry Stogov	char *base = (char *) mh_arg2;
1079a20323eSDmitry Stogov#else
1089a20323eSDmitry Stogov	char *base;
1099a20323eSDmitry Stogov
1109a20323eSDmitry Stogov	base = (char *) ts_resource(*((int *) mh_arg2));
1119a20323eSDmitry Stogov#endif
1129a20323eSDmitry Stogov
1139a20323eSDmitry Stogov	p = (zend_long *) (base+(size_t) mh_arg1);
1149a20323eSDmitry Stogov
1157aa76271SDmitry Stogov	val = zend_atol(ZSTR_VAL(new_value), (int)ZSTR_LEN(new_value));
1169a20323eSDmitry Stogov
1179a20323eSDmitry Stogov	if (stage != ZEND_INI_STAGE_STARTUP &&
1189a20323eSDmitry Stogov	    stage != ZEND_INI_STAGE_SHUTDOWN &&
1199a20323eSDmitry Stogov	    *p != val &&
1209a20323eSDmitry Stogov	    (*p < 0 || val < 0)) {
1219a20323eSDmitry Stogov		zend_error(E_WARNING, "zend.assertions may be completely enabled or disabled only in php.ini");
1229a20323eSDmitry Stogov		return FAILURE;
1239a20323eSDmitry Stogov	}
1249a20323eSDmitry Stogov
1259a20323eSDmitry Stogov	*p = val;
1269a20323eSDmitry Stogov	return SUCCESS;
1279a20323eSDmitry Stogov}
1289a20323eSDmitry Stogov/* }}} */
129bbf3d43cSMoriyoshi Koizumi
1304be862b0SZeev SuraskiZEND_INI_BEGIN()
131eb6fd52eSZeev Suraski	ZEND_INI_ENTRY("error_reporting",				NULL,		ZEND_INI_ALL,		OnUpdateErrorReporting)
1329a20323eSDmitry Stogov	STD_ZEND_INI_BOOLEAN("zend.assertions",				"1",    ZEND_INI_ALL,       OnUpdateAssertions,           assertions,   zend_executor_globals,  executor_globals)
13371592cecSDmitry Stogov	STD_ZEND_INI_BOOLEAN("zend.enable_gc",				"1",	ZEND_INI_ALL,		OnUpdateGCEnabled,      gc_enabled,     zend_gc_globals,        gc_globals)
134ab93d8c6SDmitry Stogov 	STD_ZEND_INI_BOOLEAN("zend.multibyte", "0", ZEND_INI_PERDIR, OnUpdateBool, multibyte,      zend_compiler_globals, compiler_globals)
135bbf3d43cSMoriyoshi Koizumi 	ZEND_INI_ENTRY("zend.script_encoding",			NULL,		ZEND_INI_ALL,		OnUpdateScriptEncoding)
136bbf3d43cSMoriyoshi Koizumi 	STD_ZEND_INI_BOOLEAN("zend.detect_unicode",			"1",	ZEND_INI_ALL,		OnUpdateBool, detect_unicode, zend_compiler_globals, compiler_globals)
13734d93f0cSIlia Alshanetsky#ifdef ZEND_SIGNALS
13834d93f0cSIlia Alshanetsky	STD_ZEND_INI_BOOLEAN("zend.signal_check", "0", ZEND_INI_SYSTEM, OnUpdateBool, check, zend_signal_globals_t, zend_signal_globals)
13934d93f0cSIlia Alshanetsky#endif
1404be862b0SZeev SuraskiZEND_INI_END()
1414be862b0SZeev Suraski
1424be862b0SZeev Suraski
1437a87fcbbSZeev Suraski#ifdef ZTS
144d11734b4SAnatol BelskiZEND_API int compiler_globals_id;
145d11734b4SAnatol BelskiZEND_API int executor_globals_id;
146b4892511SJani Taskinenstatic HashTable *global_function_table = NULL;
147b4892511SJani Taskinenstatic HashTable *global_class_table = NULL;
148b4892511SJani Taskinenstatic HashTable *global_constants_table = NULL;
149b4892511SJani Taskinenstatic HashTable *global_auto_globals_table = NULL;
15021698c12SDmitry Stogovstatic HashTable *global_persistent_list = NULL;
151af3ca745SAnatol BelskiZEND_TSRMLS_CACHE_DEFINE();
1527a87fcbbSZeev Suraski#endif
153573b4602SAndi Gutmans
154e801a99aSZeev SuraskiZEND_API zend_utility_values zend_uv;
155573b4602SAndi Gutmans
156573b4602SAndi Gutmans/* version information */
157573b4602SAndi Gutmansstatic char *zend_version_info;
158573b4602SAndi Gutmansstatic uint zend_version_info_length;
159fc33f52dSXinchen Hui#define ZEND_CORE_VERSION_INFO	"Zend Engine v" ZEND_VERSION ", Copyright (c) 1998-2015 Zend Technologies\n"
16080bab9d9SAndrei Zmievski#define PRINT_ZVAL_INDENT 4
161573b4602SAndi Gutmans
162bdeb220fSAnatol Belskistatic void print_hash(zend_write_func_t write_func, HashTable *ht, int indent, zend_bool is_object) /* {{{ */
163573b4602SAndi Gutmans{
164f4cfaf36SDmitry Stogov	zval *tmp;
165f4cfaf36SDmitry Stogov	zend_string *string_key;
166c3e3c98eSAnatol Belski	zend_ulong num_key;
167573b4602SAndi Gutmans	int i;
168573b4602SAndi Gutmans
169b4892511SJani Taskinen	for (i = 0; i < indent; i++) {
170d3d02fbcSDmitry Stogov		ZEND_PUTS_EX(" ");
171573b4602SAndi Gutmans	}
172d3d02fbcSDmitry Stogov	ZEND_PUTS_EX("(\n");
17380bab9d9SAndrei Zmievski	indent += PRINT_ZVAL_INDENT;
1747652a977SDmitry Stogov	ZEND_HASH_FOREACH_KEY_VAL(ht, num_key, string_key, tmp) {
175887189caSDmitry Stogov		if (Z_TYPE_P(tmp) == IS_INDIRECT) {
176887189caSDmitry Stogov			tmp = Z_INDIRECT_P(tmp);
177887189caSDmitry Stogov			if (Z_TYPE_P(tmp) == IS_UNDEF) {
178887189caSDmitry Stogov				continue;
179887189caSDmitry Stogov			}
180887189caSDmitry Stogov		}
181b4892511SJani Taskinen		for (i = 0; i < indent; i++) {
182d3d02fbcSDmitry Stogov			ZEND_PUTS_EX(" ");
183573b4602SAndi Gutmans		}
184d3d02fbcSDmitry Stogov		ZEND_PUTS_EX("[");
1857652a977SDmitry Stogov		if (string_key) {
1867652a977SDmitry Stogov			if (is_object) {
1877652a977SDmitry Stogov				const char *prop_name, *class_name;
188079409bbSNikita Popov				size_t prop_len;
189079409bbSNikita Popov				int mangled = zend_unmangle_property_name_ex(string_key, &class_name, &prop_name, &prop_len);
1907652a977SDmitry Stogov
1917652a977SDmitry Stogov				ZEND_WRITE_EX(prop_name, prop_len);
1927652a977SDmitry Stogov				if (class_name && mangled == SUCCESS) {
1937652a977SDmitry Stogov					if (class_name[0]=='*') {
1947652a977SDmitry Stogov						ZEND_PUTS_EX(":protected");
1957652a977SDmitry Stogov					} else {
1967652a977SDmitry Stogov						ZEND_PUTS_EX(":");
1977652a977SDmitry Stogov						ZEND_PUTS_EX(class_name);
1987652a977SDmitry Stogov						ZEND_PUTS_EX(":private");
199d329ce93SZeev Suraski					}
200d3d02fbcSDmitry Stogov				}
2017652a977SDmitry Stogov			} else {
2027aa76271SDmitry Stogov				ZEND_WRITE_EX(ZSTR_VAL(string_key), ZSTR_LEN(string_key));
2037652a977SDmitry Stogov			}
2047652a977SDmitry Stogov		} else {
2057652a977SDmitry Stogov			char key[25];
2064d997f63SAnatol Belski			snprintf(key, sizeof(key), ZEND_LONG_FMT, num_key);
2077652a977SDmitry Stogov			ZEND_PUTS_EX(key);
208573b4602SAndi Gutmans		}
209d3d02fbcSDmitry Stogov		ZEND_PUTS_EX("] => ");
210bdeb220fSAnatol Belski		zend_print_zval_r_ex(write_func, tmp, indent+PRINT_ZVAL_INDENT);
211d3d02fbcSDmitry Stogov		ZEND_PUTS_EX("\n");
2127652a977SDmitry Stogov	} ZEND_HASH_FOREACH_END();
21380bab9d9SAndrei Zmievski	indent -= PRINT_ZVAL_INDENT;
214b4892511SJani Taskinen	for (i = 0; i < indent; i++) {
215d3d02fbcSDmitry Stogov		ZEND_PUTS_EX(" ");
216573b4602SAndi Gutmans	}
217d3d02fbcSDmitry Stogov	ZEND_PUTS_EX(")\n");
218573b4602SAndi Gutmans}
219b4892511SJani Taskinen/* }}} */
220573b4602SAndi Gutmans
221bdeb220fSAnatol Belskistatic void print_flat_hash(HashTable *ht) /* {{{ */
22227de54b0SAndi Gutmans{
223f4cfaf36SDmitry Stogov	zval *tmp;
224f4cfaf36SDmitry Stogov	zend_string *string_key;
225c3e3c98eSAnatol Belski	zend_ulong num_key;
226b4892511SJani Taskinen	int i = 0;
227b4892511SJani Taskinen
2280ade00c8SNikita Popov	ZEND_HASH_FOREACH_KEY_VAL_IND(ht, num_key, string_key, tmp) {
229b4892511SJani Taskinen		if (i++ > 0) {
230b4892511SJani Taskinen			ZEND_PUTS(",");
231b4892511SJani Taskinen		}
232b4892511SJani Taskinen		ZEND_PUTS("[");
2337652a977SDmitry Stogov		if (string_key) {
2347aa76271SDmitry Stogov			ZEND_WRITE(ZSTR_VAL(string_key), ZSTR_LEN(string_key));
2357652a977SDmitry Stogov		} else {
2364d997f63SAnatol Belski			zend_printf(ZEND_ULONG_FMT, num_key);
237b4892511SJani Taskinen		}
238b4892511SJani Taskinen		ZEND_PUTS("] => ");
239bdeb220fSAnatol Belski		zend_print_flat_zval_r(tmp);
2407652a977SDmitry Stogov	} ZEND_HASH_FOREACH_END();
24127de54b0SAndi Gutmans}
242b4892511SJani Taskinen/* }}} */
2437a87fcbbSZeev Suraski
244bdeb220fSAnatol BelskiZEND_API int zend_make_printable_zval(zval *expr, zval *expr_copy) /* {{{ */
245573b4602SAndi Gutmans{
246f3a6c30cSXinchen Hui	if (Z_TYPE_P(expr) == IS_STRING) {
2479d6e45a0SDmitry Stogov		return 0;
24822fbfdfbSXinchen Hui	} else {
249bdeb220fSAnatol Belski		ZVAL_STR(expr_copy, _zval_get_string_func(expr));
25022fbfdfbSXinchen Hui		return 1;
251da9faa2cSZeev Suraski	}
252da9faa2cSZeev Suraski}
253b4892511SJani Taskinen/* }}} */
254da9faa2cSZeev Suraski
255bdeb220fSAnatol BelskiZEND_API size_t zend_print_zval(zval *expr, int indent) /* {{{ */
256da9faa2cSZeev Suraski{
257bdeb220fSAnatol Belski	return zend_print_zval_ex(zend_write, expr, indent);
2585dba4774SZeev Suraski}
259b4892511SJani Taskinen/* }}} */
2605dba4774SZeev Suraski
261bdeb220fSAnatol BelskiZEND_API size_t zend_print_zval_ex(zend_write_func_t write_func, zval *expr, int indent) /* {{{ */
2625dba4774SZeev Suraski{
2634ed452c1SDmitry Stogov	zend_string *str = zval_get_string(expr);
2647aa76271SDmitry Stogov	size_t len = ZSTR_LEN(str);
265da9faa2cSZeev Suraski
266bda96e3cSNikita Popov	if (len != 0) {
2677aa76271SDmitry Stogov		write_func(ZSTR_VAL(str), len);
268573b4602SAndi Gutmans	}
269bda96e3cSNikita Popov
270c3e3c98eSAnatol Belski	zend_string_release(str);
271bda96e3cSNikita Popov	return len;
272573b4602SAndi Gutmans}
273b4892511SJani Taskinen/* }}} */
274573b4602SAndi Gutmans
275bdeb220fSAnatol BelskiZEND_API void zend_print_flat_zval_r(zval *expr) /* {{{ */
27627de54b0SAndi Gutmans{
277b4892511SJani Taskinen	switch (Z_TYPE_P(expr)) {
278b4892511SJani Taskinen		case IS_ARRAY:
279b4892511SJani Taskinen			ZEND_PUTS("Array (");
280b3b616cfSDmitry Stogov			if (ZEND_HASH_APPLY_PROTECTION(Z_ARRVAL_P(expr)) &&
281b3b616cfSDmitry Stogov			    ++Z_ARRVAL_P(expr)->u.v.nApplyCount>1) {
282b4892511SJani Taskinen				ZEND_PUTS(" *RECURSION*");
28372c287bdSDmitry Stogov				Z_ARRVAL_P(expr)->u.v.nApplyCount--;
284b4892511SJani Taskinen				return;
285b4892511SJani Taskinen			}
286bdeb220fSAnatol Belski			print_flat_hash(Z_ARRVAL_P(expr));
287b4892511SJani Taskinen			ZEND_PUTS(")");
288b3b616cfSDmitry Stogov			if (ZEND_HASH_APPLY_PROTECTION(Z_ARRVAL_P(expr))) {
289b3b616cfSDmitry Stogov				Z_ARRVAL_P(expr)->u.v.nApplyCount--;
290b3b616cfSDmitry Stogov			}
291b4892511SJani Taskinen			break;
292b4892511SJani Taskinen		case IS_OBJECT:
293b4892511SJani Taskinen		{
2949bba373aSStanislav Malyshev			HashTable *properties = NULL;
295bdeb220fSAnatol Belski			zend_string *class_name = Z_OBJ_HANDLER_P(expr, get_class_name)(Z_OBJ_P(expr));
2967aa76271SDmitry Stogov			zend_printf("%s Object (", ZSTR_VAL(class_name));
297df79b9b2SNikita Popov			zend_string_release(class_name);
2988ce1211aSMarcus Boerger
299dc764bf6SNikita Popov			if (Z_OBJ_APPLY_COUNT_P(expr) > 0) {
300dc764bf6SNikita Popov				ZEND_PUTS(" *RECURSION*");
301dc764bf6SNikita Popov				return;
302dc764bf6SNikita Popov			}
303dc764bf6SNikita Popov
304f30f3590SStanislav Malyshev			if (Z_OBJ_HANDLER_P(expr, get_properties)) {
3059bba373aSStanislav Malyshev				properties = Z_OBJPROP_P(expr);
3069bba373aSStanislav Malyshev			}
307f30f3590SStanislav Malyshev			if (properties) {
308dc764bf6SNikita Popov				Z_OBJ_INC_APPLY_COUNT_P(expr);
309bdeb220fSAnatol Belski				print_flat_hash(properties);
310dc764bf6SNikita Popov				Z_OBJ_DEC_APPLY_COUNT_P(expr);
3119bba373aSStanislav Malyshev			}
3129bba373aSStanislav Malyshev			ZEND_PUTS(")");
3139bba373aSStanislav Malyshev			break;
314b4892511SJani Taskinen		}
315b4892511SJani Taskinen		default:
316bdeb220fSAnatol Belski			zend_print_variable(expr);
317b4892511SJani Taskinen			break;
318b4892511SJani Taskinen	}
31927de54b0SAndi Gutmans}
320b4892511SJani Taskinen/* }}} */
321573b4602SAndi Gutmans
322bdeb220fSAnatol BelskiZEND_API void zend_print_zval_r(zval *expr, int indent) /* {{{ */
3235dba4774SZeev Suraski{
324bdeb220fSAnatol Belski	zend_print_zval_r_ex(zend_write, expr, indent);
3255dba4774SZeev Suraski}
326b4892511SJani Taskinen/* }}} */
3275dba4774SZeev Suraski
328bdeb220fSAnatol BelskiZEND_API void zend_print_zval_r_ex(zend_write_func_t write_func, zval *expr, int indent) /* {{{ */
329573b4602SAndi Gutmans{
330c6cba554SDmitry Stogov	ZVAL_DEREF(expr);
331b4892511SJani Taskinen	switch (Z_TYPE_P(expr)) {
332573b4602SAndi Gutmans		case IS_ARRAY:
333d3d02fbcSDmitry Stogov			ZEND_PUTS_EX("Array\n");
334b3b616cfSDmitry Stogov			if (ZEND_HASH_APPLY_PROTECTION(Z_ARRVAL_P(expr)) &&
335b3b616cfSDmitry Stogov			    ++Z_ARRVAL_P(expr)->u.v.nApplyCount>1) {
336d3d02fbcSDmitry Stogov				ZEND_PUTS_EX(" *RECURSION*");
33772c287bdSDmitry Stogov				Z_ARRVAL_P(expr)->u.v.nApplyCount--;
3386053f2a1SZeev Suraski				return;
3396053f2a1SZeev Suraski			}
340bdeb220fSAnatol Belski			print_hash(write_func, Z_ARRVAL_P(expr), indent, 0);
341b3b616cfSDmitry Stogov			if (ZEND_HASH_APPLY_PROTECTION(Z_ARRVAL_P(expr))) {
342b3b616cfSDmitry Stogov				Z_ARRVAL_P(expr)->u.v.nApplyCount--;
343b3b616cfSDmitry Stogov			}
344573b4602SAndi Gutmans			break;
345573b4602SAndi Gutmans		case IS_OBJECT:
346c259cb7cSAndi Gutmans			{
3478ce1211aSMarcus Boerger				HashTable *properties;
3488ce1211aSMarcus Boerger				int is_temp;
3498ce1211aSMarcus Boerger
350bdeb220fSAnatol Belski				zend_string *class_name = Z_OBJ_HANDLER_P(expr, get_class_name)(Z_OBJ_P(expr));
3517aa76271SDmitry Stogov				ZEND_PUTS_EX(ZSTR_VAL(class_name));
352df79b9b2SNikita Popov				zend_string_release(class_name);
353df79b9b2SNikita Popov
354d3d02fbcSDmitry Stogov				ZEND_PUTS_EX(" Object\n");
355dc764bf6SNikita Popov				if (Z_OBJ_APPLY_COUNT_P(expr) > 0) {
356d3d02fbcSDmitry Stogov					ZEND_PUTS_EX(" *RECURSION*");
3578ce1211aSMarcus Boerger					return;
3588ce1211aSMarcus Boerger				}
359dc764bf6SNikita Popov				if ((properties = Z_OBJDEBUG_P(expr, is_temp)) == NULL) {
360dc764bf6SNikita Popov					break;
361dc764bf6SNikita Popov				}
362dc764bf6SNikita Popov
363dc764bf6SNikita Popov				Z_OBJ_INC_APPLY_COUNT_P(expr);
364bdeb220fSAnatol Belski				print_hash(write_func, properties, indent, 1);
365dc764bf6SNikita Popov				Z_OBJ_DEC_APPLY_COUNT_P(expr);
366dc764bf6SNikita Popov
3678ce1211aSMarcus Boerger				if (is_temp) {
3688ce1211aSMarcus Boerger					zend_hash_destroy(properties);
3694e7cbf3fSDmitry Stogov					FREE_HASHTABLE(properties);
370c259cb7cSAndi Gutmans				}
371c259cb7cSAndi Gutmans				break;
3726053f2a1SZeev Suraski			}
373573b4602SAndi Gutmans		default:
374bdeb220fSAnatol Belski			zend_print_zval_ex(write_func, expr, indent);
375573b4602SAndi Gutmans			break;
376573b4602SAndi Gutmans	}
377573b4602SAndi Gutmans}
378b4892511SJani Taskinen/* }}} */
379573b4602SAndi Gutmans
3802fa8d67aSDmitry Stogovstatic FILE *zend_fopen_wrapper(const char *filename, zend_string **opened_path) /* {{{ */
381573b4602SAndi Gutmans{
3825463dd5bSAndi Gutmans	if (opened_path) {
3832fa8d67aSDmitry Stogov		*opened_path = zend_string_init(filename, strlen(filename), 0);
3845463dd5bSAndi Gutmans	}
385f311ab16SAndi Gutmans	return fopen(filename, "rb");
386573b4602SAndi Gutmans}
387b4892511SJani Taskinen/* }}} */
388573b4602SAndi Gutmans
3892f586e96SDmitry Stogov#ifdef ZTS
390e756333bSNikita Popovstatic zend_bool short_tags_default      = 1;
3916f9f0bf2SAnatol Belskistatic uint32_t compiler_options_default = ZEND_COMPILE_DEFAULT;
3922f586e96SDmitry Stogov#else
3938c885b89SDmitry Stogov# define short_tags_default			1
3948c885b89SDmitry Stogov# define compiler_options_default	ZEND_COMPILE_DEFAULT
3952f586e96SDmitry Stogov#endif
3962f586e96SDmitry Stogov
397bdeb220fSAnatol Belskistatic void zend_set_default_compile_time_values(void) /* {{{ */
3988b794bb1SZeev Suraski{
3998b794bb1SZeev Suraski	/* default compile-time values */
4002f586e96SDmitry Stogov	CG(short_tags) = short_tags_default;
4018c885b89SDmitry Stogov	CG(compiler_options) = compiler_options_default;
4028b794bb1SZeev Suraski}
403b4892511SJani Taskinen/* }}} */
4048b794bb1SZeev Suraski
405a978a5ebSFerenc Kovacs#ifdef ZEND_WIN32
40692324b27SAnatol Belskistatic void zend_get_windows_version_info(OSVERSIONINFOEX *osvi) /* {{{ */
40792324b27SAnatol Belski{
40892324b27SAnatol Belski	ZeroMemory(osvi, sizeof(OSVERSIONINFOEX));
40992324b27SAnatol Belski	osvi->dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
41092324b27SAnatol Belski	if(!GetVersionEx((OSVERSIONINFO *) osvi)) {
411