zend.c revision fa45f64b
1573b4602SAndi Gutmans/*
2573b4602SAndi Gutmans   +----------------------------------------------------------------------+
3573b4602SAndi Gutmans   | Zend Engine                                                          |
4573b4602SAndi Gutmans   +----------------------------------------------------------------------+
59e29f841SSammy Kaye Powers   | Copyright (c) 1998-2017 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"
341b29e0caSNikita Popov#include "zend_smart_str.h"
355fc9aa9aSNikita Popov#include "zend_smart_string.h"
36573b4602SAndi Gutmans
377a87fcbbSZeev Suraski#ifdef ZTS
38cd2b462aSAnatol BelskiZEND_API int compiler_globals_id;
39cd2b462aSAnatol BelskiZEND_API int executor_globals_id;
40cd2b462aSAnatol Belskistatic HashTable *global_function_table = NULL;
41cd2b462aSAnatol Belskistatic HashTable *global_class_table = NULL;
42cd2b462aSAnatol Belskistatic HashTable *global_constants_table = NULL;
43cd2b462aSAnatol Belskistatic HashTable *global_auto_globals_table = NULL;
44cd2b462aSAnatol Belskistatic HashTable *global_persistent_list = NULL;
45cd2b462aSAnatol BelskiZEND_TSRMLS_CACHE_DEFINE()
46b4892511SJani Taskinen# define GLOBAL_FUNCTION_TABLE		global_function_table
47b4892511SJani Taskinen# define GLOBAL_CLASS_TABLE			global_class_table
48b4892511SJani Taskinen# define GLOBAL_CONSTANTS_TABLE		global_constants_table
49b4892511SJani Taskinen# define GLOBAL_AUTO_GLOBALS_TABLE	global_auto_globals_table
507a87fcbbSZeev Suraski#else
51b4892511SJani Taskinen# define GLOBAL_FUNCTION_TABLE		CG(function_table)
52b4892511SJani Taskinen# define GLOBAL_CLASS_TABLE			CG(class_table)
53b4892511SJani Taskinen# define GLOBAL_AUTO_GLOBALS_TABLE	CG(auto_globals)
54b4892511SJani Taskinen# define GLOBAL_CONSTANTS_TABLE		EG(zend_constants)
557a87fcbbSZeev Suraski#endif
567a87fcbbSZeev Suraski
57cd2b462aSAnatol BelskiZEND_API zend_utility_values zend_uv;
58fa45f64bSRemi ColletZEND_API zend_bool zend_dtrace_enabled;
59cd2b462aSAnatol Belski
60cd2b462aSAnatol Belski/* version information */
61cd2b462aSAnatol Belskistatic char *zend_version_info;
62cd2b462aSAnatol Belskistatic uint32_t zend_version_info_length;
63cd2b462aSAnatol Belski#define ZEND_CORE_VERSION_INFO	"Zend Engine v" ZEND_VERSION ", Copyright (c) 1998-2017 Zend Technologies\n"
64cd2b462aSAnatol Belski#define PRINT_ZVAL_INDENT 4
65cd2b462aSAnatol Belski
66573b4602SAndi Gutmans/* true multithread-shared globals */
6792dd5e61SStanislav MalyshevZEND_API zend_class_entry *zend_standard_class_def = NULL;
68c3e3c98eSAnatol BelskiZEND_API size_t (*zend_printf)(const char *format, ...);
695dba4774SZeev SuraskiZEND_API zend_write_func_t zend_write;
702fa8d67aSDmitry StogovZEND_API FILE *(*zend_fopen)(const char *filename, zend_string **opened_path);
71bdeb220fSAnatol BelskiZEND_API int (*zend_stream_open_function)(const char *filename, zend_file_handle *handle);
72bdeb220fSAnatol BelskiZEND_API void (*zend_ticks_function)(int ticks);
73d0460d8fSDmitry StogovZEND_API void (*zend_interrupt_function)(zend_execute_data *execute_data);
74b204b3abSAnatol BelskiZEND_API void (*zend_error_cb)(int type, const char *error_filename, const uint32_t error_lineno, const char *format, va_list args);
755fc9aa9aSNikita Popovvoid (*zend_printf_to_smart_string)(smart_string *buf, const char *format, va_list ap);
765fc9aa9aSNikita Popovvoid (*zend_printf_to_smart_str)(smart_str *buf, const char *format, va_list ap);
77bdeb220fSAnatol BelskiZEND_API char *(*zend_getenv)(char *name, size_t name_len);
782fa8d67aSDmitry StogovZEND_API zend_string *(*zend_resolve_path)(const char *filename, int filename_len);
79536221beSStanislav Malyshev
80bdeb220fSAnatol Belskivoid (*zend_on_timeout)(int seconds);
81bd115087SZeev Suraski
82bdeb220fSAnatol Belskistatic void (*zend_message_dispatcher_p)(zend_long message, const void *data);
8388d7ca44SDmitry Stogovstatic zval *(*zend_get_configuration_directive_p)(zend_string *name);
84d035af4aSZeev Suraski
85b4892511SJani Taskinenstatic ZEND_INI_MH(OnUpdateErrorReporting) /* {{{ */
864be862b0SZeev Suraski{
874be862b0SZeev Suraski	if (!new_value) {
88d3e50265SMarcus Boerger		EG(error_reporting) = E_ALL & ~E_NOTICE & ~E_STRICT & ~E_DEPRECATED;
894be862b0SZeev Suraski	} else {
907aa76271SDmitry Stogov		EG(error_reporting) = atoi(ZSTR_VAL(new_value));
914be862b0SZeev Suraski	}
924be862b0SZeev Suraski	return SUCCESS;
934be862b0SZeev Suraski}
94b4892511SJani Taskinen/* }}} */
954be862b0SZeev Suraski
9671592cecSDmitry Stogovstatic ZEND_INI_MH(OnUpdateGCEnabled) /* {{{ */
9771592cecSDmitry Stogov{
98bdeb220fSAnatol Belski	OnUpdateBool(entry, new_value, mh_arg1, mh_arg2, mh_arg3, stage);
9971592cecSDmitry Stogov
10071592cecSDmitry Stogov	if (GC_G(gc_enabled)) {
101bdeb220fSAnatol Belski		gc_init();
10271592cecSDmitry Stogov	}
10371592cecSDmitry Stogov
10471592cecSDmitry Stogov	return SUCCESS;
10571592cecSDmitry Stogov}
10671592cecSDmitry Stogov/* }}} */
10771592cecSDmitry Stogov
108bbf3d43cSMoriyoshi Koizumistatic ZEND_INI_MH(OnUpdateScriptEncoding) /* {{{ */
109bbf3d43cSMoriyoshi Koizumi{
110e46852d2SAnatol Belski	if (!CG(multibyte)) {
111bbf3d43cSMoriyoshi Koizumi		return FAILURE;
112bbf3d43cSMoriyoshi Koizumi	}
113bdeb220fSAnatol Belski	if (!zend_multibyte_get_functions()) {
114bbf3d43cSMoriyoshi Koizumi		return SUCCESS;
115bbf3d43cSMoriyoshi Koizumi	}
1167aa76271SDmitry Stogov	return zend_multibyte_set_script_encoding_by_string(new_value ? ZSTR_VAL(new_value) : NULL, new_value ? ZSTR_LEN(new_value) : 0);
117bbf3d43cSMoriyoshi Koizumi}
118bbf3d43cSMoriyoshi Koizumi/* }}} */
119bbf3d43cSMoriyoshi Koizumi
1209a20323eSDmitry Stogovstatic ZEND_INI_MH(OnUpdateAssertions) /* {{{ */
1219a20323eSDmitry Stogov{
1229a20323eSDmitry Stogov	zend_long *p, val;
1239a20323eSDmitry Stogov#ifndef ZTS
1249a20323eSDmitry Stogov	char *base = (char *) mh_arg2;
1259a20323eSDmitry Stogov#else
1269a20323eSDmitry Stogov	char *base;
1279a20323eSDmitry Stogov
1289a20323eSDmitry Stogov	base = (char *) ts_resource(*((int *) mh_arg2));
1299a20323eSDmitry Stogov#endif
1309a20323eSDmitry Stogov
1319a20323eSDmitry Stogov	p = (zend_long *) (base+(size_t) mh_arg1);
1329a20323eSDmitry Stogov
1337aa76271SDmitry Stogov	val = zend_atol(ZSTR_VAL(new_value), (int)ZSTR_LEN(new_value));
1349a20323eSDmitry Stogov
1359a20323eSDmitry Stogov	if (stage != ZEND_INI_STAGE_STARTUP &&
1369a20323eSDmitry Stogov	    stage != ZEND_INI_STAGE_SHUTDOWN &&
1379a20323eSDmitry Stogov	    *p != val &&
1389a20323eSDmitry Stogov	    (*p < 0 || val < 0)) {
1399a20323eSDmitry Stogov		zend_error(E_WARNING, "zend.assertions may be completely enabled or disabled only in php.ini");
1409a20323eSDmitry Stogov		return FAILURE;
1419a20323eSDmitry Stogov	}
1429a20323eSDmitry Stogov
1439a20323eSDmitry Stogov	*p = val;
1449a20323eSDmitry Stogov	return SUCCESS;
1459a20323eSDmitry Stogov}
1469a20323eSDmitry Stogov/* }}} */
147bbf3d43cSMoriyoshi Koizumi
1484be862b0SZeev SuraskiZEND_INI_BEGIN()
149eb6fd52eSZeev Suraski	ZEND_INI_ENTRY("error_reporting",				NULL,		ZEND_INI_ALL,		OnUpdateErrorReporting)
150fb2c890cSRasmus Lerdorf	STD_ZEND_INI_ENTRY("zend.assertions",				"1",    ZEND_INI_ALL,       OnUpdateAssertions,           assertions,   zend_executor_globals,  executor_globals)
15171592cecSDmitry Stogov	STD_ZEND_INI_BOOLEAN("zend.enable_gc",				"1",	ZEND_INI_ALL,		OnUpdateGCEnabled,      gc_enabled,     zend_gc_globals,        gc_globals)
152ab93d8c6SDmitry Stogov 	STD_ZEND_INI_BOOLEAN("zend.multibyte", "0", ZEND_INI_PERDIR, OnUpdateBool, multibyte,      zend_compiler_globals, compiler_globals)
153bbf3d43cSMoriyoshi Koizumi 	ZEND_INI_ENTRY("zend.script_encoding",			NULL,		ZEND_INI_ALL,		OnUpdateScriptEncoding)
154bbf3d43cSMoriyoshi Koizumi 	STD_ZEND_INI_BOOLEAN("zend.detect_unicode",			"1",	ZEND_INI_ALL,		OnUpdateBool, detect_unicode, zend_compiler_globals, compiler_globals)
15534d93f0cSIlia Alshanetsky#ifdef ZEND_SIGNALS
15634d93f0cSIlia Alshanetsky	STD_ZEND_INI_BOOLEAN("zend.signal_check", "0", ZEND_INI_SYSTEM, OnUpdateBool, check, zend_signal_globals_t, zend_signal_globals)
15734d93f0cSIlia Alshanetsky#endif
1584be862b0SZeev SuraskiZEND_INI_END()
1594be862b0SZeev Suraski
1605fc9aa9aSNikita PopovZEND_API size_t zend_vspprintf(char **pbuf, size_t max_len, const char *format, va_list ap) /* {{{ */
1615fc9aa9aSNikita Popov{
1625fc9aa9aSNikita Popov	smart_string buf = {0};
1635fc9aa9aSNikita Popov
1645fc9aa9aSNikita Popov	/* since there are places where (v)spprintf called without checking for null,
1655fc9aa9aSNikita Popov	   a bit of defensive coding here */
1665fc9aa9aSNikita Popov	if (!pbuf) {
1675fc9aa9aSNikita Popov		return 0;
1685fc9aa9aSNikita Popov	}
1695fc9aa9aSNikita Popov
1705fc9aa9aSNikita Popov	zend_printf_to_smart_string(&buf, format, ap);
1715fc9aa9aSNikita Popov
1725fc9aa9aSNikita Popov	if (max_len && buf.len > max_len) {
1735fc9aa9aSNikita Popov		buf.len = max_len;
1745fc9aa9aSNikita Popov	}
1755fc9aa9aSNikita Popov
1765fc9aa9aSNikita Popov	smart_string_0(&buf);
1775fc9aa9aSNikita Popov
1785fc9aa9aSNikita Popov	if (buf.c) {
1795fc9aa9aSNikita Popov		*pbuf = buf.c;
1805fc9aa9aSNikita Popov		return buf.len;
1815fc9aa9aSNikita Popov	} else {
1825fc9aa9aSNikita Popov		*pbuf = estrndup("", 0);
1835fc9aa9aSNikita Popov		return 0;
1845fc9aa9aSNikita Popov	}
1855fc9aa9aSNikita Popov}
1865fc9aa9aSNikita Popov/* }}} */
1875fc9aa9aSNikita Popov
188c7742e28SNikita PopovZEND_API size_t zend_spprintf(char **message, size_t max_len, const char *format, ...) /* {{{ */
189c7742e28SNikita Popov{
190c7742e28SNikita Popov	va_list arg;
191c7742e28SNikita Popov	size_t len;
192c7742e28SNikita Popov
193c7742e28SNikita Popov	va_start(arg, format);
194c7742e28SNikita Popov	len = zend_vspprintf(message, max_len, format, arg);
195c7742e28SNikita Popov	va_end(arg);
196c7742e28SNikita Popov	return len;
197c7742e28SNikita Popov}
198c7742e28SNikita Popov/* }}} */
199c7742e28SNikita Popov
2005fc9aa9aSNikita PopovZEND_API zend_string *zend_vstrpprintf(size_t max_len, const char *format, va_list ap) /* {{{ */
2015fc9aa9aSNikita Popov{
2025fc9aa9aSNikita Popov	smart_str buf = {0};
2035fc9aa9aSNikita Popov
2045fc9aa9aSNikita Popov	zend_printf_to_smart_str(&buf, format, ap);
2055fc9aa9aSNikita Popov
2065fc9aa9aSNikita Popov	if (!buf.s) {
2075fc9aa9aSNikita Popov		return ZSTR_EMPTY_ALLOC();
2085fc9aa9aSNikita Popov	}
2095fc9aa9aSNikita Popov
2105fc9aa9aSNikita Popov	if (max_len && ZSTR_LEN(buf.s) > max_len) {
2115fc9aa9aSNikita Popov		ZSTR_LEN(buf.s) = max_len;
2125fc9aa9aSNikita Popov	}
2135fc9aa9aSNikita Popov
2145fc9aa9aSNikita Popov	smart_str_0(&buf);
2155fc9aa9aSNikita Popov	return buf.s;
2165fc9aa9aSNikita Popov}
2175fc9aa9aSNikita Popov/* }}} */
2185fc9aa9aSNikita Popov
219c7742e28SNikita PopovZEND_API zend_string *zend_strpprintf(size_t max_len, const char *format, ...) /* {{{ */
220c7742e28SNikita Popov{
221c7742e28SNikita Popov	va_list arg;
222c7742e28SNikita Popov	zend_string *str;
223c7742e28SNikita Popov
224c7742e28SNikita Popov	va_start(arg, format);
225c7742e28SNikita Popov	str = zend_vstrpprintf(max_len, format, arg);
226c7742e28SNikita Popov	va_end(arg);
227c7742e28SNikita Popov	return str;
228c7742e28SNikita Popov}
229c7742e28SNikita Popov/* }}} */
230c7742e28SNikita Popov
2311b29e0caSNikita Popovstatic void zend_print_zval_r_to_buf(smart_str *buf, zval *expr, int indent);
2321b29e0caSNikita Popov
2331b29e0caSNikita Popovstatic void print_hash(smart_str *buf, HashTable *ht, int indent, zend_bool is_object) /* {{{ */
234573b4602SAndi Gutmans{
235f4cfaf36SDmitry Stogov	zval *tmp;
236f4cfaf36SDmitry Stogov	zend_string *string_key;
237c3e3c98eSAnatol Belski	zend_ulong num_key;
238573b4602SAndi Gutmans	int i;
239573b4602SAndi Gutmans
240b4892511SJani Taskinen	for (i = 0; i < indent; i++) {
2411b29e0caSNikita Popov		smart_str_appendc(buf, ' ');
242573b4602SAndi Gutmans	}
2431b29e0caSNikita Popov	smart_str_appends(buf, "(\n");
24480bab9d9SAndrei Zmievski	indent += PRINT_ZVAL_INDENT;
2451b29e0caSNikita Popov	ZEND_HASH_FOREACH_KEY_VAL_IND(ht, num_key, string_key, tmp) {
246b4892511SJani Taskinen		for (i = 0; i < indent; i++) {
2471b29e0caSNikita Popov			smart_str_appendc(buf, ' ');
248573b4602SAndi Gutmans		}
2491b29e0caSNikita Popov		smart_str_appendc(buf, '[');
2507652a977SDmitry Stogov		if (string_key) {
2517652a977SDmitry Stogov			if (is_object) {
2527652a977SDmitry Stogov				const char *prop_name, *class_name;
253079409bbSNikita Popov				size_t prop_len;
254079409bbSNikita Popov				int mangled = zend_unmangle_property_name_ex(string_key, &class_name, &prop_name, &prop_len);
2557652a977SDmitry Stogov
2561b29e0caSNikita Popov				smart_str_appendl(buf, prop_name, prop_len);
2577652a977SDmitry Stogov				if (class_name && mangled == SUCCESS) {
2581b29e0caSNikita Popov					if (class_name[0] == '*') {
2591b29e0caSNikita Popov						smart_str_appends(buf, ":protected");
2607652a977SDmitry Stogov					} else {
2611b29e0caSNikita Popov						smart_str_appends(buf, ":");
2621b29e0caSNikita Popov						smart_str_appends(buf, class_name);
2631b29e0caSNikita Popov						smart_str_appends(buf, ":private");
264d329ce93SZeev Suraski					}
265d3d02fbcSDmitry Stogov				}
2667652a977SDmitry Stogov			} else {
2671b29e0caSNikita Popov				smart_str_append(buf, string_key);
2687652a977SDmitry Stogov			}
2697652a977SDmitry Stogov		} else {
2701b29e0caSNikita Popov			smart_str_append_long(buf, num_key);
271573b4602SAndi Gutmans		}
2721b29e0caSNikita Popov		smart_str_appends(buf, "] => ");
2731b29e0caSNikita Popov		zend_print_zval_r_to_buf(buf, tmp, indent+PRINT_ZVAL_INDENT);
2741b29e0caSNikita Popov		smart_str_appends(buf, "\n");
2757652a977SDmitry Stogov	} ZEND_HASH_FOREACH_END();
27680bab9d9SAndrei Zmievski	indent -= PRINT_ZVAL_INDENT;
277b4892511SJani Taskinen	for (i = 0; i < indent; i++) {
2781b29e0caSNikita Popov		smart_str_appendc(buf, ' ');
279573b4602SAndi Gutmans	}
2801b29e0caSNikita Popov	smart_str_appends(buf, ")\n");
281573b4602SAndi Gutmans}
282b4892511SJani Taskinen/* }}} */
283573b4602SAndi Gutmans
284bdeb220fSAnatol Belskistatic void print_flat_hash(HashTable *ht) /* {{{ */
28527de54b0SAndi Gutmans{
286f4cfaf36SDmitry Stogov	zval *tmp;
287f4cfaf36SDmitry Stogov	zend_string *string_key;
288c3e3c98eSAnatol Belski	zend_ulong num_key;
289b4892511SJani Taskinen	int i = 0;
290b4892511SJani Taskinen
2910ade00c8SNikita Popov	ZEND_HASH_FOREACH_KEY_VAL_IND(ht, num_key, string_key, tmp) {
292b4892511SJani Taskinen		if (i++ > 0) {
293b4892511SJani Taskinen			ZEND_PUTS(",");
294b4892511SJani Taskinen		}
295b4892511SJani Taskinen		ZEND_PUTS("[");
2967652a977SDmitry Stogov		if (string_key) {
2977aa76271SDmitry Stogov			ZEND_WRITE(ZSTR_VAL(string_key), ZSTR_LEN(string_key));
2987652a977SDmitry Stogov		} else {
2994d997f63SAnatol Belski			zend_printf(ZEND_ULONG_FMT, num_key);
300b4892511SJani Taskinen		}
301b4892511SJani Taskinen		ZEND_PUTS("] => ");
302bdeb220fSAnatol Belski		zend_print_flat_zval_r(tmp);
3037652a977SDmitry Stogov	} ZEND_HASH_FOREACH_END();
30427de54b0SAndi Gutmans}
305b4892511SJani Taskinen/* }}} */
3067a87fcbbSZeev Suraski
307bdeb220fSAnatol BelskiZEND_API int zend_make_printable_zval(zval *expr, zval *expr_copy) /* {{{ */
308573b4602SAndi Gutmans{
309f3a6c30cSXinchen Hui	if (Z_TYPE_P(expr) == IS_STRING) {
3109d6e45a0SDmitry Stogov		return 0;
31122fbfdfbSXinchen Hui	} else {
312bdeb220fSAnatol Belski		ZVAL_STR(expr_copy, _zval_get_string_func(expr));
31322fbfdfbSXinchen Hui		return 1;
314da9faa2cSZeev Suraski	}
315da9faa2cSZeev Suraski}
316b4892511SJani Taskinen/* }}} */
317da9faa2cSZeev Suraski
318bdeb220fSAnatol BelskiZEND_API size_t zend_print_zval(zval *expr, int indent) /* {{{ */
319da9faa2cSZeev Suraski{
3204ed452c1SDmitry Stogov	zend_string *str = zval_get_string(expr);
3217aa76271SDmitry Stogov	size_t len = ZSTR_LEN(str);
322da9faa2cSZeev Suraski
323bda96e3cSNikita Popov	if (len != 0) {
3241b29e0caSNikita Popov		zend_write(ZSTR_VAL(str), len);
325573b4602SAndi Gutmans	}
326bda96e3cSNikita Popov
327c3e3c98eSAnatol Belski	zend_string_release(str);
328bda96e3cSNikita Popov	return len;
329573b4602SAndi Gutmans}
330b4892511SJani Taskinen/* }}} */
331573b4602SAndi Gutmans
332bdeb220fSAnatol BelskiZEND_API void zend_print_flat_zval_r(zval *expr) /* {{{ */
33327de54b0SAndi Gutmans{
334b4892511SJani Taskinen	switch (Z_TYPE_P(expr)) {
335b4892511SJani Taskinen		case IS_ARRAY:
336b4892511SJani Taskinen			ZEND_PUTS("Array (");
337b3b616cfSDmitry Stogov			if (ZEND_HASH_APPLY_PROTECTION(Z_ARRVAL_P(expr)) &&
338b3b616cfSDmitry Stogov			    ++Z_ARRVAL_P(expr)->u.v.nApplyCount>1) {
339b4892511SJani Taskinen				ZEND_PUTS(" *RECURSION*");
34072c287bdSDmitry Stogov				Z_ARRVAL_P(expr)->u.v.nApplyCount--;
341b4892511SJani Taskinen				return;
342b4892511SJani Taskinen			}
343bdeb220fSAnatol Belski			print_flat_hash(Z_ARRVAL_P(expr));
344b4892511SJani Taskinen			ZEND_PUTS(")");
345b3b616cfSDmitry Stogov			if (ZEND_HASH_APPLY_PROTECTION(Z_ARRVAL_P(expr))) {
346b3b616cfSDmitry Stogov				Z_ARRVAL_P(expr)->u.v.nApplyCount--;
347b3b616cfSDmitry Stogov			}
348b4892511SJani Taskinen			break;
349b4892511SJani Taskinen		case IS_OBJECT:
350b4892511SJani Taskinen		{
3519bba373aSStanislav Malyshev			HashTable *properties = NULL;
352bdeb220fSAnatol Belski			zend_string *class_name = Z_OBJ_HANDLER_P(expr, get_class_name)(Z_OBJ_P(expr));
3537aa76271SDmitry Stogov			zend_printf("%s Object (", ZSTR_VAL(class_name));
354df79b9b2SNikita Popov			zend_string_release(class_name);
3558ce1211aSMarcus Boerger
356dc764bf6SNikita Popov			if (Z_OBJ_APPLY_COUNT_P(expr) > 0) {
357dc764bf6SNikita Popov				ZEND_PUTS(" *RECURSION*");
358dc764bf6SNikita Popov				return;
359dc764bf6SNikita Popov			}
360dc764bf6SNikita Popov
361f30f3590SStanislav Malyshev			if (Z_OBJ_HANDLER_P(expr, get_properties)) {
3629bba373aSStanislav Malyshev				properties = Z_OBJPROP_P(expr);
3639bba373aSStanislav Malyshev			}
364f30f3590SStanislav Malyshev			if (properties) {
365dc764bf6SNikita Popov				Z_OBJ_INC_APPLY_COUNT_P(expr);
366bdeb220fSAnatol Belski				print_flat_hash(properties);
367dc764bf6SNikita Popov				Z_OBJ_DEC_APPLY_COUNT_P(expr);
3689bba373aSStanislav Malyshev			}
3699bba373aSStanislav Malyshev			ZEND_PUTS(")");
3709bba373aSStanislav Malyshev			break;
371b4892511SJani Taskinen		}
372b0037688SBob Weinand		case IS_REFERENCE:
373b0037688SBob Weinand			zend_print_flat_zval_r(Z_REFVAL_P(expr));
374b0037688SBob Weinand			break;
375b4892511SJani Taskinen		default:
376bdeb220fSAnatol Belski			zend_print_variable(expr);
377b4892511SJani Taskinen			break;
378b4892511SJani Taskinen	}
37927de54b0SAndi Gutmans}
380b4892511SJani Taskinen/* }}} */
381573b4602SAndi Gutmans
3821b29e0caSNikita Popovstatic void zend_print_zval_r_to_buf(smart_str *buf, zval *expr, int indent) /* {{{ */
383573b4602SAndi Gutmans{
384b4892511SJani Taskinen	switch (Z_TYPE_P(expr)) {
385573b4602SAndi Gutmans		case IS_ARRAY:
3861b29e0caSNikita Popov			smart_str_appends(buf, "Array\n");
387b3b616cfSDmitry Stogov			if (ZEND_HASH_APPLY_PROTECTION(Z_ARRVAL_P(expr)) &&
388b3b616cfSDmitry Stogov			    ++Z_ARRVAL_P(expr)->u.v.nApplyCount>1) {
3891b29e0caSNikita Popov				smart_str_appends(buf, " *RECURSION*");
39072c287bdSDmitry Stogov				Z_ARRVAL_P(expr)->u.v.nApplyCount--;
3916053f2a1SZeev Suraski				return;
3926053f2a1SZeev Suraski			}
3931b29e0caSNikita Popov			print_hash(buf, Z_ARRVAL_P(expr), indent, 0);
394b3b616cfSDmitry Stogov			if (ZEND_HASH_APPLY_PROTECTION(Z_ARRVAL_P(expr))) {
395b3b616cfSDmitry Stogov				Z_ARRVAL_P(expr)->u.v.nApplyCount--;
396b3b616cfSDmitry Stogov			}
397573b4602SAndi Gutmans			break;
398573b4602SAndi Gutmans		case IS_OBJECT:
399c259cb7cSAndi Gutmans			{
4008ce1211aSMarcus Boerger				HashTable *properties;
4018ce1211aSMarcus Boerger				int is_temp;
4028ce1211aSMarcus Boerger
403bdeb220fSAnatol Belski				zend_string *class_name = Z_OBJ_HANDLER_P(expr, get_class_name)(Z_OBJ_P(expr));
4041b29e0caSNikita Popov				smart_str_appends(buf, ZSTR_VAL(class_name));
405df79b9b2SNikita Popov				zend_string_release(class_name);
406