zend.c revision 5fc9aa9a
1573b4602SAndi Gutmans/*
2573b4602SAndi Gutmans   +----------------------------------------------------------------------+
3573b4602SAndi Gutmans   | Zend Engine                                                          |
4573b4602SAndi Gutmans   +----------------------------------------------------------------------+
597a9470dSXinchen Hui   | Copyright (c) 1998-2016 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
38b4892511SJani Taskinen# define GLOBAL_FUNCTION_TABLE		global_function_table
39b4892511SJani Taskinen# define GLOBAL_CLASS_TABLE			global_class_table
40b4892511SJani Taskinen# define GLOBAL_CONSTANTS_TABLE		global_constants_table
41b4892511SJani Taskinen# define GLOBAL_AUTO_GLOBALS_TABLE	global_auto_globals_table
427a87fcbbSZeev Suraski#else
43b4892511SJani Taskinen# define GLOBAL_FUNCTION_TABLE		CG(function_table)
44b4892511SJani Taskinen# define GLOBAL_CLASS_TABLE			CG(class_table)
45b4892511SJani Taskinen# define GLOBAL_AUTO_GLOBALS_TABLE	CG(auto_globals)
46b4892511SJani Taskinen# define GLOBAL_CONSTANTS_TABLE		EG(zend_constants)
477a87fcbbSZeev Suraski#endif
487a87fcbbSZeev Suraski
49573b4602SAndi Gutmans/* true multithread-shared globals */
5092dd5e61SStanislav MalyshevZEND_API zend_class_entry *zend_standard_class_def = NULL;
51c3e3c98eSAnatol BelskiZEND_API size_t (*zend_printf)(const char *format, ...);
525dba4774SZeev SuraskiZEND_API zend_write_func_t zend_write;
532fa8d67aSDmitry StogovZEND_API FILE *(*zend_fopen)(const char *filename, zend_string **opened_path);
54bdeb220fSAnatol BelskiZEND_API int (*zend_stream_open_function)(const char *filename, zend_file_handle *handle);
55bdeb220fSAnatol BelskiZEND_API void (*zend_ticks_function)(int ticks);
56d0460d8fSDmitry StogovZEND_API void (*zend_interrupt_function)(zend_execute_data *execute_data);
57b204b3abSAnatol BelskiZEND_API void (*zend_error_cb)(int type, const char *error_filename, const uint32_t error_lineno, const char *format, va_list args);
585fc9aa9aSNikita Popovvoid (*zend_printf_to_smart_string)(smart_string *buf, const char *format, va_list ap);
595fc9aa9aSNikita Popovvoid (*zend_printf_to_smart_str)(smart_str *buf, const char *format, va_list ap);
60bdeb220fSAnatol BelskiZEND_API char *(*zend_getenv)(char *name, size_t name_len);
612fa8d67aSDmitry StogovZEND_API zend_string *(*zend_resolve_path)(const char *filename, int filename_len);
62536221beSStanislav Malyshev
63bdeb220fSAnatol Belskivoid (*zend_on_timeout)(int seconds);
64bd115087SZeev Suraski
65bdeb220fSAnatol Belskistatic void (*zend_message_dispatcher_p)(zend_long message, const void *data);
6688d7ca44SDmitry Stogovstatic zval *(*zend_get_configuration_directive_p)(zend_string *name);
67d035af4aSZeev Suraski
68b4892511SJani Taskinenstatic ZEND_INI_MH(OnUpdateErrorReporting) /* {{{ */
694be862b0SZeev Suraski{
704be862b0SZeev Suraski	if (!new_value) {
71d3e50265SMarcus Boerger		EG(error_reporting) = E_ALL & ~E_NOTICE & ~E_STRICT & ~E_DEPRECATED;
724be862b0SZeev Suraski	} else {
737aa76271SDmitry Stogov		EG(error_reporting) = atoi(ZSTR_VAL(new_value));
744be862b0SZeev Suraski	}
754be862b0SZeev Suraski	return SUCCESS;
764be862b0SZeev Suraski}
77b4892511SJani Taskinen/* }}} */
784be862b0SZeev Suraski
7971592cecSDmitry Stogovstatic ZEND_INI_MH(OnUpdateGCEnabled) /* {{{ */
8071592cecSDmitry Stogov{
81bdeb220fSAnatol Belski	OnUpdateBool(entry, new_value, mh_arg1, mh_arg2, mh_arg3, stage);
8271592cecSDmitry Stogov
8371592cecSDmitry Stogov	if (GC_G(gc_enabled)) {
84bdeb220fSAnatol Belski		gc_init();
8571592cecSDmitry Stogov	}
8671592cecSDmitry Stogov
8771592cecSDmitry Stogov	return SUCCESS;
8871592cecSDmitry Stogov}
8971592cecSDmitry Stogov/* }}} */
9071592cecSDmitry Stogov
91bbf3d43cSMoriyoshi Koizumistatic ZEND_INI_MH(OnUpdateScriptEncoding) /* {{{ */
92bbf3d43cSMoriyoshi Koizumi{
93e46852d2SAnatol Belski	if (!CG(multibyte)) {
94bbf3d43cSMoriyoshi Koizumi		return FAILURE;
95bbf3d43cSMoriyoshi Koizumi	}
96bdeb220fSAnatol Belski	if (!zend_multibyte_get_functions()) {
97bbf3d43cSMoriyoshi Koizumi		return SUCCESS;
98bbf3d43cSMoriyoshi Koizumi	}
997aa76271SDmitry Stogov	return zend_multibyte_set_script_encoding_by_string(new_value ? ZSTR_VAL(new_value) : NULL, new_value ? ZSTR_LEN(new_value) : 0);
100bbf3d43cSMoriyoshi Koizumi}
101bbf3d43cSMoriyoshi Koizumi/* }}} */
102bbf3d43cSMoriyoshi Koizumi
1039a20323eSDmitry Stogovstatic ZEND_INI_MH(OnUpdateAssertions) /* {{{ */
1049a20323eSDmitry Stogov{
1059a20323eSDmitry Stogov	zend_long *p, val;
1069a20323eSDmitry Stogov#ifndef ZTS
1079a20323eSDmitry Stogov	char *base = (char *) mh_arg2;
1089a20323eSDmitry Stogov#else
1099a20323eSDmitry Stogov	char *base;
1109a20323eSDmitry Stogov
1119a20323eSDmitry Stogov	base = (char *) ts_resource(*((int *) mh_arg2));
1129a20323eSDmitry Stogov#endif
1139a20323eSDmitry Stogov
1149a20323eSDmitry Stogov	p = (zend_long *) (base+(size_t) mh_arg1);
1159a20323eSDmitry Stogov
1167aa76271SDmitry Stogov	val = zend_atol(ZSTR_VAL(new_value), (int)ZSTR_LEN(new_value));
1179a20323eSDmitry Stogov
1189a20323eSDmitry Stogov	if (stage != ZEND_INI_STAGE_STARTUP &&
1199a20323eSDmitry Stogov	    stage != ZEND_INI_STAGE_SHUTDOWN &&
1209a20323eSDmitry Stogov	    *p != val &&
1219a20323eSDmitry Stogov	    (*p < 0 || val < 0)) {
1229a20323eSDmitry Stogov		zend_error(E_WARNING, "zend.assertions may be completely enabled or disabled only in php.ini");
1239a20323eSDmitry Stogov		return FAILURE;
1249a20323eSDmitry Stogov	}
1259a20323eSDmitry Stogov
1269a20323eSDmitry Stogov	*p = val;
1279a20323eSDmitry Stogov	return SUCCESS;
1289a20323eSDmitry Stogov}
1299a20323eSDmitry Stogov/* }}} */
130bbf3d43cSMoriyoshi Koizumi
1314be862b0SZeev SuraskiZEND_INI_BEGIN()
132eb6fd52eSZeev Suraski	ZEND_INI_ENTRY("error_reporting",				NULL,		ZEND_INI_ALL,		OnUpdateErrorReporting)
133fb2c890cSRasmus Lerdorf	STD_ZEND_INI_ENTRY("zend.assertions",				"1",    ZEND_INI_ALL,       OnUpdateAssertions,           assertions,   zend_executor_globals,  executor_globals)
13471592cecSDmitry Stogov	STD_ZEND_INI_BOOLEAN("zend.enable_gc",				"1",	ZEND_INI_ALL,		OnUpdateGCEnabled,      gc_enabled,     zend_gc_globals,        gc_globals)
135ab93d8c6SDmitry Stogov 	STD_ZEND_INI_BOOLEAN("zend.multibyte", "0", ZEND_INI_PERDIR, OnUpdateBool, multibyte,      zend_compiler_globals, compiler_globals)
136bbf3d43cSMoriyoshi Koizumi 	ZEND_INI_ENTRY("zend.script_encoding",			NULL,		ZEND_INI_ALL,		OnUpdateScriptEncoding)
137bbf3d43cSMoriyoshi Koizumi 	STD_ZEND_INI_BOOLEAN("zend.detect_unicode",			"1",	ZEND_INI_ALL,		OnUpdateBool, detect_unicode, zend_compiler_globals, compiler_globals)
13834d93f0cSIlia Alshanetsky#ifdef ZEND_SIGNALS
13934d93f0cSIlia Alshanetsky	STD_ZEND_INI_BOOLEAN("zend.signal_check", "0", ZEND_INI_SYSTEM, OnUpdateBool, check, zend_signal_globals_t, zend_signal_globals)
14034d93f0cSIlia Alshanetsky#endif
1414be862b0SZeev SuraskiZEND_INI_END()
1424be862b0SZeev Suraski
1434be862b0SZeev Suraski
1447a87fcbbSZeev Suraski#ifdef ZTS
145d11734b4SAnatol BelskiZEND_API int compiler_globals_id;
146d11734b4SAnatol BelskiZEND_API int executor_globals_id;
147b4892511SJani Taskinenstatic HashTable *global_function_table = NULL;
148b4892511SJani Taskinenstatic HashTable *global_class_table = NULL;
149b4892511SJani Taskinenstatic HashTable *global_constants_table = NULL;
150b4892511SJani Taskinenstatic HashTable *global_auto_globals_table = NULL;
15121698c12SDmitry Stogovstatic HashTable *global_persistent_list = NULL;
1521ac15293SNikita PopovZEND_TSRMLS_CACHE_DEFINE()
1537a87fcbbSZeev Suraski#endif
154573b4602SAndi Gutmans
155e801a99aSZeev SuraskiZEND_API zend_utility_values zend_uv;
156573b4602SAndi Gutmans
157573b4602SAndi Gutmans/* version information */
158573b4602SAndi Gutmansstatic char *zend_version_info;
159b204b3abSAnatol Belskistatic uint32_t zend_version_info_length;
16097a9470dSXinchen Hui#define ZEND_CORE_VERSION_INFO	"Zend Engine v" ZEND_VERSION ", Copyright (c) 1998-2016 Zend Technologies\n"
16180bab9d9SAndrei Zmievski#define PRINT_ZVAL_INDENT 4
162573b4602SAndi Gutmans
1635fc9aa9aSNikita PopovZEND_API size_t zend_vspprintf(char **pbuf, size_t max_len, const char *format, va_list ap) /* {{{ */
1645fc9aa9aSNikita Popov{
1655fc9aa9aSNikita Popov	smart_string buf = {0};
1665fc9aa9aSNikita Popov
1675fc9aa9aSNikita Popov	/* since there are places where (v)spprintf called without checking for null,
1685fc9aa9aSNikita Popov	   a bit of defensive coding here */
1695fc9aa9aSNikita Popov	if (!pbuf) {
1705fc9aa9aSNikita Popov		return 0;
1715fc9aa9aSNikita Popov	}
1725fc9aa9aSNikita Popov
1735fc9aa9aSNikita Popov	zend_printf_to_smart_string(&buf, format, ap);
1745fc9aa9aSNikita Popov
1755fc9aa9aSNikita Popov	if (max_len && buf.len > max_len) {
1765fc9aa9aSNikita Popov		buf.len = max_len;
1775fc9aa9aSNikita Popov	}
1785fc9aa9aSNikita Popov
1795fc9aa9aSNikita Popov	smart_string_0(&buf);
1805fc9aa9aSNikita Popov
1815fc9aa9aSNikita Popov	if (buf.c) {
1825fc9aa9aSNikita Popov		*pbuf = buf.c;
1835fc9aa9aSNikita Popov		return buf.len;
1845fc9aa9aSNikita Popov	} else {
1855fc9aa9aSNikita Popov		*pbuf = estrndup("", 0);
1865fc9aa9aSNikita Popov		return 0;
1875fc9aa9aSNikita Popov	}
1885fc9aa9aSNikita Popov}
1895fc9aa9aSNikita Popov/* }}} */
1905fc9aa9aSNikita Popov
191c7742e28SNikita PopovZEND_API size_t zend_spprintf(char **message, size_t max_len, const char *format, ...) /* {{{ */
192c7742e28SNikita Popov{
193c7742e28SNikita Popov	va_list arg;
194c7742e28SNikita Popov	size_t len;
195c7742e28SNikita Popov
196c7742e28SNikita Popov	va_start(arg, format);
197c7742e28SNikita Popov	len = zend_vspprintf(message, max_len, format, arg);
198c7742e28SNikita Popov	va_end(arg);
199c7742e28SNikita Popov	return len;
200c7742e28SNikita Popov}
201c7742e28SNikita Popov/* }}} */
202c7742e28SNikita Popov
2035fc9aa9aSNikita PopovZEND_API zend_string *zend_vstrpprintf(size_t max_len, const char *format, va_list ap) /* {{{ */
2045fc9aa9aSNikita Popov{
2055fc9aa9aSNikita Popov	smart_str buf = {0};
2065fc9aa9aSNikita Popov
2075fc9aa9aSNikita Popov	zend_printf_to_smart_str(&buf, format, ap);
2085fc9aa9aSNikita Popov
2095fc9aa9aSNikita Popov	if (!buf.s) {
2105fc9aa9aSNikita Popov		return ZSTR_EMPTY_ALLOC();
2115fc9aa9aSNikita Popov	}
2125fc9aa9aSNikita Popov
2135fc9aa9aSNikita Popov	if (max_len && ZSTR_LEN(buf.s) > max_len) {
2145fc9aa9aSNikita Popov		ZSTR_LEN(buf.s) = max_len;
2155fc9aa9aSNikita Popov	}
2165fc9aa9aSNikita Popov
2175fc9aa9aSNikita Popov	smart_str_0(&buf);
2185fc9aa9aSNikita Popov	return buf.s;
2195fc9aa9aSNikita Popov}
2205fc9aa9aSNikita Popov/* }}} */
2215fc9aa9aSNikita Popov
222c7742e28SNikita PopovZEND_API zend_string *zend_strpprintf(size_t max_len, const char *format, ...) /* {{{ */
223c7742e28SNikita Popov{
224c7742e28SNikita Popov	va_list arg;
225c7742e28SNikita Popov	zend_string *str;
226c7742e28SNikita Popov
227c7742e28SNikita Popov	va_start(arg, format);
228c7742e28SNikita Popov	str = zend_vstrpprintf(max_len, format, arg);
229c7742e28SNikita Popov	va_end(arg);
230c7742e28SNikita Popov	return str;
231c7742e28SNikita Popov}
232c7742e28SNikita Popov/* }}} */
233c7742e28SNikita Popov
2341b29e0caSNikita Popovstatic void zend_print_zval_r_to_buf(smart_str *buf, zval *expr, int indent);
2351b29e0caSNikita Popov
2361b29e0caSNikita Popovstatic void print_hash(smart_str *buf, HashTable *ht, int indent, zend_bool is_object) /* {{{ */
237573b4602SAndi Gutmans{
238f4cfaf36SDmitry Stogov	zval *tmp;
239f4cfaf36SDmitry Stogov	zend_string *string_key;
240c3e3c98eSAnatol Belski	zend_ulong num_key;
241573b4602SAndi Gutmans	int i;
242573b4602SAndi Gutmans
243b4892511SJani Taskinen	for (i = 0; i < indent; i++) {
2441b29e0caSNikita Popov		smart_str_appendc(buf, ' ');
245573b4602SAndi Gutmans	}
2461b29e0caSNikita Popov	smart_str_appends(buf, "(\n");
24780bab9d9SAndrei Zmievski	indent += PRINT_ZVAL_INDENT;
2481b29e0caSNikita Popov	ZEND_HASH_FOREACH_KEY_VAL_IND(ht, num_key, string_key, tmp) {
249b4892511SJani Taskinen		for (i = 0; i < indent; i++) {
2501b29e0caSNikita Popov			smart_str_appendc(buf, ' ');
251573b4602SAndi Gutmans		}
2521b29e0caSNikita Popov		smart_str_appendc(buf, '[');
2537652a977SDmitry Stogov		if (string_key) {
2547652a977SDmitry Stogov			if (is_object) {
2557652a977SDmitry Stogov				const char *prop_name, *class_name;
256079409bbSNikita Popov				size_t prop_len;
257079409bbSNikita Popov				int mangled = zend_unmangle_property_name_ex(string_key, &class_name, &prop_name, &prop_len);
2587652a977SDmitry Stogov
2591b29e0caSNikita Popov				smart_str_appendl(buf, prop_name, prop_len);
2607652a977SDmitry Stogov				if (class_name && mangled == SUCCESS) {
2611b29e0caSNikita Popov					if (class_name[0] == '*') {
2621b29e0caSNikita Popov						smart_str_appends(buf, ":protected");
2637652a977SDmitry Stogov					} else {
2641b29e0caSNikita Popov						smart_str_appends(buf, ":");
2651b29e0caSNikita Popov						smart_str_appends(buf, class_name);
2661b29e0caSNikita Popov						smart_str_appends(buf, ":private");
267d329ce93SZeev Suraski					}
268d3d02fbcSDmitry Stogov				}
2697652a977SDmitry Stogov			} else {
2701b29e0caSNikita Popov				smart_str_append(buf, string_key);
2717652a977SDmitry Stogov			}
2727652a977SDmitry Stogov		} else {
2731b29e0caSNikita Popov			smart_str_append_long(buf, num_key);
274573b4602SAndi Gutmans		}
2751b29e0caSNikita Popov		smart_str_appends(buf, "] => ");
2761b29e0caSNikita Popov		zend_print_zval_r_to_buf(buf, tmp, indent+PRINT_ZVAL_INDENT);
2771b29e0caSNikita Popov		smart_str_appends(buf, "\n");
2787652a977SDmitry Stogov	} ZEND_HASH_FOREACH_END();
27980bab9d9SAndrei Zmievski	indent -= PRINT_ZVAL_INDENT;
280b4892511SJani Taskinen	for (i = 0; i < indent; i++) {
2811b29e0caSNikita Popov		smart_str_appendc(buf, ' ');
282573b4602SAndi Gutmans	}
2831b29e0caSNikita Popov	smart_str_appends(buf, ")\n");
284573b4602SAndi Gutmans}
285b4892511SJani Taskinen/* }}} */
286573b4602SAndi Gutmans
287bdeb220fSAnatol Belskistatic void print_flat_hash(HashTable *ht) /* {{{ */
28827de54b0SAndi Gutmans{
289f4cfaf36SDmitry Stogov	zval *tmp;
290f4cfaf36SDmitry Stogov	zend_string *string_key;
291c3e3c98eSAnatol Belski	zend_ulong num_key;
292b4892511SJani Taskinen	int i = 0;
293b4892511SJani Taskinen
2940ade00c8SNikita Popov	ZEND_HASH_FOREACH_KEY_VAL_IND(ht, num_key, string_key, tmp) {
295b4892511SJani Taskinen		if (i++ > 0) {
296b4892511SJani Taskinen			ZEND_PUTS(",");
297b4892511SJani Taskinen		}
298b4892511SJani Taskinen		ZEND_PUTS("[");
2997652a977SDmitry Stogov		if (string_key) {
3007aa76271SDmitry Stogov			ZEND_WRITE(ZSTR_VAL(string_key), ZSTR_LEN(string_key));
3017652a977SDmitry Stogov		} else {
3024d997f63SAnatol Belski			zend_printf(ZEND_ULONG_FMT, num_key);
303b4892511SJani Taskinen		}
304b4892511SJani Taskinen		ZEND_PUTS("] => ");
305bdeb220fSAnatol Belski		zend_print_flat_zval_r(tmp);
3067652a977SDmitry Stogov	} ZEND_HASH_FOREACH_END();
30727de54b0SAndi Gutmans}
308b4892511SJani Taskinen/* }}} */
3097a87fcbbSZeev Suraski
310bdeb220fSAnatol BelskiZEND_API int zend_make_printable_zval(zval *expr, zval *expr_copy) /* {{{ */
311573b4602SAndi Gutmans{
312f3a6c30cSXinchen Hui	if (Z_TYPE_P(expr) == IS_STRING) {
3139d6e45a0SDmitry Stogov		return 0;
31422fbfdfbSXinchen Hui	} else {
315bdeb220fSAnatol Belski		ZVAL_STR(expr_copy, _zval_get_string_func(expr));
31622fbfdfbSXinchen Hui		return 1;
317da9faa2cSZeev Suraski	}
318da9faa2cSZeev Suraski}
319b4892511SJani Taskinen/* }}} */
320da9faa2cSZeev Suraski
321bdeb220fSAnatol BelskiZEND_API size_t zend_print_zval(zval *expr, int indent) /* {{{ */
322da9faa2cSZeev Suraski{
3234ed452c1SDmitry Stogov	zend_string *str = zval_get_string(expr);
3247aa76271SDmitry Stogov	size_t len = ZSTR_LEN(str);
325da9faa2cSZeev Suraski
326bda96e3cSNikita Popov	if (len != 0) {
3271b29e0caSNikita Popov		zend_write(ZSTR_VAL(str), len);
328573b4602SAndi Gutmans	}
329bda96e3cSNikita Popov
330c3e3c98eSAnatol Belski	zend_string_release(str);
331bda96e3cSNikita Popov	return len;
332573b4602SAndi Gutmans}
333b4892511SJani Taskinen/* }}} */
334573b4602SAndi Gutmans
335bdeb220fSAnatol BelskiZEND_API void zend_print_flat_zval_r(zval *expr) /* {{{ */
33627de54b0SAndi Gutmans{
337b4892511SJani Taskinen	switch (Z_TYPE_P(expr)) {
338b4892511SJani Taskinen		case IS_ARRAY:
339b4892511SJani Taskinen			ZEND_PUTS("Array (");
340b3b616cfSDmitry Stogov			if (ZEND_HASH_APPLY_PROTECTION(Z_ARRVAL_P(expr)) &&
341b3b616cfSDmitry Stogov			    ++Z_ARRVAL_P(expr)->u.v.nApplyCount>1) {
342b4892511SJani Taskinen				ZEND_PUTS(" *RECURSION*");
34372c287bdSDmitry Stogov				Z_ARRVAL_P(expr)->u.v.nApplyCount--;
344b4892511SJani Taskinen				return;
345b4892511SJani Taskinen			}
346bdeb220fSAnatol Belski			print_flat_hash(Z_ARRVAL_P(expr));
347b4892511SJani Taskinen			ZEND_PUTS(")");
348b3b616cfSDmitry Stogov			if (ZEND_HASH_APPLY_PROTECTION(Z_ARRVAL_P(expr))) {
349b3b616cfSDmitry Stogov				Z_ARRVAL_P(expr)->u.v.nApplyCount--;
350b3b616cfSDmitry Stogov			}
351b4892511SJani Taskinen			break;
352b4892511SJani Taskinen		case IS_OBJECT:
353b4892511SJani Taskinen		{
3549bba373aSStanislav Malyshev			HashTable *properties = NULL;
355bdeb220fSAnatol Belski			zend_string *class_name = Z_OBJ_HANDLER_P(expr, get_class_name)(Z_OBJ_P(expr));
3567aa76271SDmitry Stogov			zend_printf("%s Object (", ZSTR_VAL(class_name));
357df79b9b2SNikita Popov			zend_string_release(class_name);
3588ce1211aSMarcus Boerger
359dc764bf6SNikita Popov			if (Z_OBJ_APPLY_COUNT_P(expr) > 0) {
360dc764bf6SNikita Popov				ZEND_PUTS(" *RECURSION*");
361dc764bf6SNikita Popov				return;
362dc764bf6SNikita Popov			}
363dc764bf6SNikita Popov
364f30f3590SStanislav Malyshev			if (Z_OBJ_HANDLER_P(expr, get_properties)) {
3659bba373aSStanislav Malyshev				properties = Z_OBJPROP_P(expr);
3669bba373aSStanislav Malyshev			}
367f30f3590SStanislav Malyshev			if (properties) {
368dc764bf6SNikita Popov				Z_OBJ_INC_APPLY_COUNT_P(expr);
369bdeb220fSAnatol Belski				print_flat_hash(properties);
370dc764bf6SNikita Popov				Z_OBJ_DEC_APPLY_COUNT_P(expr);
3719bba373aSStanislav Malyshev			}
3729bba373aSStanislav Malyshev			ZEND_PUTS(")");
3739bba373aSStanislav Malyshev			break;
374b4892511SJani Taskinen		}
375b0037688SBob Weinand		case IS_REFERENCE:
376b0037688SBob Weinand			zend_print_flat_zval_r(Z_REFVAL_P(expr));
377b0037688SBob Weinand			break;
378b4892511SJani Taskinen		default:
379bdeb220fSAnatol Belski			zend_print_variable(expr);
380b4892511SJani Taskinen			break;
381b4892511SJani Taskinen	}
38227de54b0SAndi Gutmans}
383b4892511SJani Taskinen/* }}} */
384573b4602SAndi Gutmans
3851b29e0caSNikita Popovstatic void zend_print_zval_r_to_buf(smart_str *buf, zval *expr, int indent) /* {{{ */
386573b4602SAndi Gutmans{
387c6cba554SDmitry Stogov	ZVAL_DEREF(expr);
388b4892511SJani Taskinen	switch (Z_TYPE_P(expr)) {
389573b4602SAndi Gutmans		case IS_ARRAY:
3901b29e0caSNikita Popov			smart_str_appends(buf, "Array\n");
391b3b616cfSDmitry Stogov			if (ZEND_HASH_APPLY_PROTECTION(Z_ARRVAL_P(expr)) &&
392b3b616cfSDmitry Stogov			    ++Z_ARRVAL_P(expr)->u.v.nApplyCount>1) {
3931b29e0caSNikita Popov				smart_str_appends(buf, " *RECURSION*");
39472c287bdSDmitry Stogov				Z_ARRVAL_P(expr)->u.v.nApplyCount--;
3956053f2a1SZeev Suraski				return;
3966053f2a1SZeev Suraski			}
3971b29e0caSNikita Popov			print_hash(buf, Z_ARRVAL_P(expr), indent</