zend.c revision b4903aef
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);
7849d9b301SAnatol BelskiZEND_API zend_string *(*zend_resolve_path)(const char *filename, size_t filename_len);
79b4903aefSDmitry StogovZEND_API int (*zend_post_startup_cb)(void) = NULL;
80536221beSStanislav Malyshev
81bdeb220fSAnatol Belskivoid (*zend_on_timeout)(int seconds);
82bd115087SZeev Suraski
83bdeb220fSAnatol Belskistatic void (*zend_message_dispatcher_p)(zend_long message, const void *data);
8488d7ca44SDmitry Stogovstatic zval *(*zend_get_configuration_directive_p)(zend_string *name);
85d035af4aSZeev Suraski
86b4892511SJani Taskinenstatic ZEND_INI_MH(OnUpdateErrorReporting) /* {{{ */
874be862b0SZeev Suraski{
884be862b0SZeev Suraski	if (!new_value) {
89d3e50265SMarcus Boerger		EG(error_reporting) = E_ALL & ~E_NOTICE & ~E_STRICT & ~E_DEPRECATED;
904be862b0SZeev Suraski	} else {
917aa76271SDmitry Stogov		EG(error_reporting) = atoi(ZSTR_VAL(new_value));
924be862b0SZeev Suraski	}
934be862b0SZeev Suraski	return SUCCESS;
944be862b0SZeev Suraski}
95b4892511SJani Taskinen/* }}} */
964be862b0SZeev Suraski
9771592cecSDmitry Stogovstatic ZEND_INI_MH(OnUpdateGCEnabled) /* {{{ */
9871592cecSDmitry Stogov{
99bdeb220fSAnatol Belski	OnUpdateBool(entry, new_value, mh_arg1, mh_arg2, mh_arg3, stage);
10071592cecSDmitry Stogov
10171592cecSDmitry Stogov	if (GC_G(gc_enabled)) {
102bdeb220fSAnatol Belski		gc_init();
10371592cecSDmitry Stogov	}
10471592cecSDmitry Stogov
10571592cecSDmitry Stogov	return SUCCESS;
10671592cecSDmitry Stogov}
10771592cecSDmitry Stogov/* }}} */
10871592cecSDmitry Stogov
109bbf3d43cSMoriyoshi Koizumistatic ZEND_INI_MH(OnUpdateScriptEncoding) /* {{{ */
110bbf3d43cSMoriyoshi Koizumi{
111e46852d2SAnatol Belski	if (!CG(multibyte)) {
112bbf3d43cSMoriyoshi Koizumi		return FAILURE;
113bbf3d43cSMoriyoshi Koizumi	}
114bdeb220fSAnatol Belski	if (!zend_multibyte_get_functions()) {
115bbf3d43cSMoriyoshi Koizumi		return SUCCESS;
116bbf3d43cSMoriyoshi Koizumi	}
1177aa76271SDmitry Stogov	return zend_multibyte_set_script_encoding_by_string(new_value ? ZSTR_VAL(new_value) : NULL, new_value ? ZSTR_LEN(new_value) : 0);
118bbf3d43cSMoriyoshi Koizumi}
119bbf3d43cSMoriyoshi Koizumi/* }}} */
120bbf3d43cSMoriyoshi Koizumi
1219a20323eSDmitry Stogovstatic ZEND_INI_MH(OnUpdateAssertions) /* {{{ */
1229a20323eSDmitry Stogov{
1239a20323eSDmitry Stogov	zend_long *p, val;
1249a20323eSDmitry Stogov#ifndef ZTS
1259a20323eSDmitry Stogov	char *base = (char *) mh_arg2;
1269a20323eSDmitry Stogov#else
1279a20323eSDmitry Stogov	char *base;
1289a20323eSDmitry Stogov
1299a20323eSDmitry Stogov	base = (char *) ts_resource(*((int *) mh_arg2));
1309a20323eSDmitry Stogov#endif
1319a20323eSDmitry Stogov
1329a20323eSDmitry Stogov	p = (zend_long *) (base+(size_t) mh_arg1);
1339a20323eSDmitry Stogov
1340d1eeeb6SAnatol Belski	val = zend_atol(ZSTR_VAL(new_value), ZSTR_LEN(new_value));
1359a20323eSDmitry Stogov
1369a20323eSDmitry Stogov	if (stage != ZEND_INI_STAGE_STARTUP &&
1379a20323eSDmitry Stogov	    stage != ZEND_INI_STAGE_SHUTDOWN &&
1389a20323eSDmitry Stogov	    *p != val &&
1399a20323eSDmitry Stogov	    (*p < 0 || val < 0)) {
1409a20323eSDmitry Stogov		zend_error(E_WARNING, "zend.assertions may be completely enabled or disabled only in php.ini");
1419a20323eSDmitry Stogov		return FAILURE;
1429a20323eSDmitry Stogov	}
1439a20323eSDmitry Stogov
1449a20323eSDmitry Stogov	*p = val;
1459a20323eSDmitry Stogov	return SUCCESS;
1469a20323eSDmitry Stogov}
1479a20323eSDmitry Stogov/* }}} */
148bbf3d43cSMoriyoshi Koizumi
1494be862b0SZeev SuraskiZEND_INI_BEGIN()
150eb6fd52eSZeev Suraski	ZEND_INI_ENTRY("error_reporting",				NULL,		ZEND_INI_ALL,		OnUpdateErrorReporting)
151fb2c890cSRasmus Lerdorf	STD_ZEND_INI_ENTRY("zend.assertions",				"1",    ZEND_INI_ALL,       OnUpdateAssertions,           assertions,   zend_executor_globals,  executor_globals)
15271592cecSDmitry Stogov	STD_ZEND_INI_BOOLEAN("zend.enable_gc",				"1",	ZEND_INI_ALL,		OnUpdateGCEnabled,      gc_enabled,     zend_gc_globals,        gc_globals)
153ab93d8c6SDmitry Stogov 	STD_ZEND_INI_BOOLEAN("zend.multibyte", "0", ZEND_INI_PERDIR, OnUpdateBool, multibyte,      zend_compiler_globals, compiler_globals)
154bbf3d43cSMoriyoshi Koizumi 	ZEND_INI_ENTRY("zend.script_encoding",			NULL,		ZEND_INI_ALL,		OnUpdateScriptEncoding)
155bbf3d43cSMoriyoshi Koizumi 	STD_ZEND_INI_BOOLEAN("zend.detect_unicode",			"1",	ZEND_INI_ALL,		OnUpdateBool, detect_unicode, zend_compiler_globals, compiler_globals)
15634d93f0cSIlia Alshanetsky#ifdef ZEND_SIGNALS
15734d93f0cSIlia Alshanetsky	STD_ZEND_INI_BOOLEAN("zend.signal_check", "0", ZEND_INI_SYSTEM, OnUpdateBool, check, zend_signal_globals_t, zend_signal_globals)
15834d93f0cSIlia Alshanetsky#endif
1594be862b0SZeev SuraskiZEND_INI_END()
1604be862b0SZeev Suraski
1615fc9aa9aSNikita PopovZEND_API size_t zend_vspprintf(char **pbuf, size_t max_len, const char *format, va_list ap) /* {{{ */
1625fc9aa9aSNikita Popov{
1635fc9aa9aSNikita Popov	smart_string buf = {0};
1645fc9aa9aSNikita Popov
1655fc9aa9aSNikita Popov	/* since there are places where (v)spprintf called without checking for null,
1665fc9aa9aSNikita Popov	   a bit of defensive coding here */
1675fc9aa9aSNikita Popov	if (!pbuf) {
1685fc9aa9aSNikita Popov		return 0;
1695fc9aa9aSNikita Popov	}
1705fc9aa9aSNikita Popov
1715fc9aa9aSNikita Popov	zend_printf_to_smart_string(&buf, format, ap);
1725fc9aa9aSNikita Popov
1735fc9aa9aSNikita Popov	if (max_len && buf.len > max_len) {
1745fc9aa9aSNikita Popov		buf.len = max_len;
1755fc9aa9aSNikita Popov	}
1765fc9aa9aSNikita Popov
1775fc9aa9aSNikita Popov	smart_string_0(&buf);
1785fc9aa9aSNikita Popov
1795fc9aa9aSNikita Popov	if (buf.c) {
1805fc9aa9aSNikita Popov		*pbuf = buf.c;
1815fc9aa9aSNikita Popov		return buf.len;
1825fc9aa9aSNikita Popov	} else {
1835fc9aa9aSNikita Popov		*pbuf = estrndup("", 0);
1845fc9aa9aSNikita Popov		return 0;
1855fc9aa9aSNikita Popov	}
1865fc9aa9aSNikita Popov}
1875fc9aa9aSNikita Popov/* }}} */
1885fc9aa9aSNikita Popov
189c7742e28SNikita PopovZEND_API size_t zend_spprintf(char **message, size_t max_len, const char *format, ...) /* {{{ */
190c7742e28SNikita Popov{
191c7742e28SNikita Popov	va_list arg;
192c7742e28SNikita Popov	size_t len;
193c7742e28SNikita Popov
194c7742e28SNikita Popov	va_start(arg, format);
195c7742e28SNikita Popov	len = zend_vspprintf(message, max_len, format, arg);
196c7742e28SNikita Popov	va_end(arg);
197c7742e28SNikita Popov	return len;
198c7742e28SNikita Popov}
199c7742e28SNikita Popov/* }}} */
200c7742e28SNikita Popov
2015fc9aa9aSNikita PopovZEND_API zend_string *zend_vstrpprintf(size_t max_len, const char *format, va_list ap) /* {{{ */
2025fc9aa9aSNikita Popov{
2035fc9aa9aSNikita Popov	smart_str buf = {0};
2045fc9aa9aSNikita Popov
2055fc9aa9aSNikita Popov	zend_printf_to_smart_str(&buf, format, ap);
2065fc9aa9aSNikita Popov
2075fc9aa9aSNikita Popov	if (!buf.s) {
2085fc9aa9aSNikita Popov		return ZSTR_EMPTY_ALLOC();
2095fc9aa9aSNikita Popov	}
2105fc9aa9aSNikita Popov
2115fc9aa9aSNikita Popov	if (max_len && ZSTR_LEN(buf.s) > max_len) {
2125fc9aa9aSNikita Popov		ZSTR_LEN(buf.s) = max_len;
2135fc9aa9aSNikita Popov	}
2145fc9aa9aSNikita Popov
2155fc9aa9aSNikita Popov	smart_str_0(&buf);
2165fc9aa9aSNikita Popov	return buf.s;
2175fc9aa9aSNikita Popov}
2185fc9aa9aSNikita Popov/* }}} */
2195fc9aa9aSNikita Popov
220c7742e28SNikita PopovZEND_API zend_string *zend_strpprintf(size_t max_len, const char *format, ...) /* {{{ */
221c7742e28SNikita Popov{
222c7742e28SNikita Popov	va_list arg;
223c7742e28SNikita Popov	zend_string *str;
224c7742e28SNikita Popov
225c7742e28SNikita Popov	va_start(arg, format);
226c7742e28SNikita Popov	str = zend_vstrpprintf(max_len, format, arg);
227c7742e28SNikita Popov	va_end(arg);
228c7742e28SNikita Popov	return str;
229c7742e28SNikita Popov}
230c7742e28SNikita Popov/* }}} */
231c7742e28SNikita Popov
2321b29e0caSNikita Popovstatic void zend_print_zval_r_to_buf(smart_str *buf, zval *expr, int indent);
2331b29e0caSNikita Popov
2341b29e0caSNikita Popovstatic void print_hash(smart_str *buf, HashTable *ht, int indent, zend_bool is_object) /* {{{ */
235573b4602SAndi Gutmans{
236f4cfaf36SDmitry Stogov	zval *tmp;
237f4cfaf36SDmitry Stogov	zend_string *string_key;
238c3e3c98eSAnatol Belski	zend_ulong num_key;
239573b4602SAndi Gutmans	int i;
240573b4602SAndi Gutmans
241b4892511SJani Taskinen	for (i = 0; i < indent; i++) {
2421b29e0caSNikita Popov		smart_str_appendc(buf, ' ');
243573b4602SAndi Gutmans	}
2441b29e0caSNikita Popov	smart_str_appends(buf, "(\n");
24580bab9d9SAndrei Zmievski	indent += PRINT_ZVAL_INDENT;
2461b29e0caSNikita Popov	ZEND_HASH_FOREACH_KEY_VAL_IND(ht, num_key, string_key, tmp) {
247b4892511SJani Taskinen		for (i = 0; i < indent; i++) {
2481b29e0caSNikita Popov			smart_str_appendc(buf, ' ');
249573b4602SAndi Gutmans		}
2501b29e0caSNikita Popov		smart_str_appendc(buf, '[');
2517652a977SDmitry Stogov		if (string_key) {
2527652a977SDmitry Stogov			if (is_object) {
2537652a977SDmitry Stogov				const char *prop_name, *class_name;
254079409bbSNikita Popov				size_t prop_len;
255079409bbSNikita Popov				int mangled = zend_unmangle_property_name_ex(string_key, &class_name, &prop_name, &prop_len);
2567652a977SDmitry Stogov
2571b29e0caSNikita Popov				smart_str_appendl(buf, prop_name, prop_len);
2587652a977SDmitry Stogov				if (class_name && mangled == SUCCESS) {
2591b29e0caSNikita Popov					if (class_name[0] == '*') {
2601b29e0caSNikita Popov						smart_str_appends(buf, ":protected");
2617652a977SDmitry Stogov					} else {
2621b29e0caSNikita Popov						smart_str_appends(buf, ":");
2631b29e0caSNikita Popov						smart_str_appends(buf, class_name);
2641b29e0caSNikita Popov						smart_str_appends(buf, ":private");
265d329ce93SZeev Suraski					}
266d3d02fbcSDmitry Stogov				}
2677652a977SDmitry Stogov			} else {
2681b29e0caSNikita Popov				smart_str_append(buf, string_key);
2697652a977SDmitry Stogov			}
2707652a977SDmitry Stogov		} else {
2711b29e0caSNikita Popov			smart_str_append_long(buf, num_key);
272573b4602SAndi Gutmans		}
2731b29e0caSNikita Popov		smart_str_appends(buf, "] => ");
2741b29e0caSNikita Popov		zend_print_zval_r_to_buf(buf, tmp, indent+PRINT_ZVAL_INDENT);
2751b29e0caSNikita Popov		smart_str_appends(buf, "\n");
2767652a977SDmitry Stogov	} ZEND_HASH_FOREACH_END();
27780bab9d9SAndrei Zmievski	indent -= PRINT_ZVAL_INDENT;
278b4892511SJani Taskinen	for (i = 0; i < indent; i++) {
2791b29e0caSNikita Popov		smart_str_appendc(buf, ' ');
280573b4602SAndi Gutmans	}
2811b29e0caSNikita Popov	smart_str_appends(buf, ")\n");
282573b4602SAndi Gutmans}
283b4892511SJani Taskinen/* }}} */
284573b4602SAndi Gutmans
285bdeb220fSAnatol Belskistatic void print_flat_hash(HashTable *ht) /* {{{ */
28627de54b0SAndi Gutmans{
287f4cfaf36SDmitry Stogov	zval *tmp;
288f4cfaf36SDmitry Stogov	zend_string *string_key;
289c3e3c98eSAnatol Belski	zend_ulong num_key;
290b4892511SJani Taskinen	int i = 0;
291b4892511SJani Taskinen
2920ade00c8SNikita Popov	ZEND_HASH_FOREACH_KEY_VAL_IND(ht, num_key, string_key, tmp) {
293b4892511SJani Taskinen		if (i++ > 0) {
294b4892511SJani Taskinen			ZEND_PUTS(",");
295b4892511SJani Taskinen		}
296b4892511SJani Taskinen		ZEND_PUTS("[");
2977652a977SDmitry Stogov		if (string_key) {
2987aa76271SDmitry Stogov			ZEND_WRITE(ZSTR_VAL(string_key), ZSTR_LEN(string_key));
2997652a977SDmitry Stogov		} else {
3004d997f63SAnatol Belski			zend_printf(ZEND_ULONG_FMT, num_key);
301b4892511SJani Taskinen		}
302b4892511SJani Taskinen		ZEND_PUTS("] => ");
303bdeb220fSAnatol Belski		zend_print_flat_zval_r(tmp);
3047652a977SDmitry Stogov	} ZEND_HASH_FOREACH_END();
30527de54b0SAndi Gutmans}
306b4892511SJani Taskinen/* }}} */
3077a87fcbbSZeev Suraski
308bdeb220fSAnatol BelskiZEND_API int zend_make_printable_zval(zval *expr, zval *expr_copy) /* {{{ */
309573b4602SAndi Gutmans{
310f3a6c30cSXinchen Hui	if (Z_TYPE_P(expr) == IS_STRING) {
3119d6e45a0SDmitry Stogov		return 0;
31222fbfdfbSXinchen Hui	} else {
313bdeb220fSAnatol Belski		ZVAL_STR(expr_copy, _zval_get_string_func(expr));
31422fbfdfbSXinchen Hui		return 1;
315da9faa2cSZeev Suraski	}
316da9faa2cSZeev Suraski}
317b4892511SJani Taskinen/* }}} */
318da9faa2cSZeev Suraski
319bdeb220fSAnatol BelskiZEND_API size_t zend_print_zval(zval *expr, int indent) /* {{{ */
320da9faa2cSZeev Suraski{
3214ed452c1SDmitry Stogov	zend_string *str = zval_get_string(expr);
3227aa76271SDmitry Stogov	size_t len = ZSTR_LEN(str);
323da9faa2cSZeev Suraski
324bda96e3cSNikita Popov	if (len != 0) {
3251b29e0caSNikita Popov		zend_write(ZSTR_VAL(str), len);
326573b4602SAndi Gutmans	}
327bda96e3cSNikita Popov
328c3e3c98eSAnatol Belski	zend_string_release(str);
329bda96e3cSNikita Popov	return len;
330573b4602SAndi Gutmans}
331b4892511SJani Taskinen/* }}} */
332573b4602SAndi Gutmans
333bdeb220fSAnatol BelskiZEND_API void zend_print_flat_zval_r(zval *expr) /* {{{ */
33427de54b0SAndi Gutmans{
335b4892511SJani Taskinen	switch (Z_TYPE_P(expr)) {
336b4892511SJani Taskinen		case IS_ARRAY:
337b4892511SJani Taskinen			ZEND_PUTS("Array (");
338cb9d81efSDmitry Stogov			if (Z_REFCOUNTED_P(expr)) {
339cb9d81efSDmitry Stogov				if (Z_IS_RECURSIVE_P(expr)) {
340cb9d81efSDmitry Stogov					ZEND_PUTS(" *RECURSION*");
341cb9d81efSDmitry Stogov					return;
342cb9d81efSDmitry Stogov				}
343cb9d81efSDmitry Stogov				Z_PROTECT_RECURSION_P(expr);
344b4892511SJani Taskinen			}
345bdeb220fSAnatol Belski			print_flat_hash(Z_ARRVAL_P(expr));
346b4892511SJani Taskinen			ZEND_PUTS(")");
347cb9d81efSDmitry Stogov			if (Z_REFCOUNTED_P(expr)) {
348cb9d81efSDmitry Stogov				Z_UNPROTECT_RECURSION_P(expr);
349b3b616cfSDmitry Stogov			}
350b4892511SJani Taskinen			break;
351b4892511SJani Taskinen		case IS_OBJECT:
352b4892511SJani Taskinen		{
3539bba373aSStanislav Malyshev			HashTable *properties = NULL;
354bdeb220fSAnatol Belski			zend_string *class_name = Z_OBJ_HANDLER_P(expr, get_class_name)(Z_OBJ_P(expr));
3557aa76271SDmitry Stogov			zend_printf("%s Object (", ZSTR_VAL(class_name));
356df79b9b2SNikita Popov			zend_string_release(class_name);
3578ce1211aSMarcus Boerger
358cb9d81efSDmitry Stogov			if (Z_IS_RECURSIVE_P(expr)) {
359dc764bf6SNikita Popov				ZEND_PUTS(" *RECURSION*");
360dc764bf6SNikita Popov				return;
361dc764bf6SNikita Popov			}
362dc764bf6SNikita Popov
363f30f3590SStanislav Malyshev			if (Z_OBJ_HANDLER_P(expr, get_properties)) {
3649bba373aSStanislav Malyshev				properties = Z_OBJPROP_P(expr);
3659bba373aSStanislav Malyshev			}
366f30f3590SStanislav Malyshev			if (properties) {
367cb9d81efSDmitry Stogov				Z_PROTECT_RECURSION_P(expr);
368bdeb220fSAnatol Belski				print_flat_hash(properties);
369cb9d81efSDmitry Stogov				Z_UNPROTECT_RECURSION_P(expr);
3709bba373aSStanislav Malyshev			}
3719bba373aSStanislav Malyshev			ZEND_PUTS(")");
3729bba373aSStanislav Malyshev			break;
373b4892511SJani Taskinen		}
374b0037688SBob Weinand		case IS_REFERENCE:
375b0037688SBob Weinand			zend_print_flat_zval_r(Z_REFVAL_P(expr));
376b0037688SBob Weinand			break;
377b4892511SJani Taskinen		default:
378bdeb220fSAnatol Belski			zend_print_variable(expr);
379b4892511SJani Taskinen			break;
380b4892511SJani Taskinen	}
38127de54b0SAndi Gutmans}
382b4892511SJani Taskinen/* }}} */
383573b4602SAndi Gutmans
3841b29e0caSNikita Popovstatic void zend_print_zval_r_to_buf(smart_str *buf, zval *expr, int indent) /* {{{ */
385573b4602SAndi Gutmans{
386b4892511SJani Taskinen	switch (Z_TYPE_P(expr)) {
387573b4602SAndi Gutmans		case IS_ARRAY:
3881b29e0caSNikita Popov			smart_str_appends(buf, "Array\n");
389cb9d81efSDmitry Stogov			if (Z_REFCOUNTED_P(expr)) {
390cb9d81efSDmitry Stogov				if (Z_IS_RECURSIVE_P(expr)) {
391cb9d81efSDmitry Stogov					smart_str_appends(buf, " *RECURSION*");
392cb9d81efSDmitry Stogov					return;
393cb9d81efSDmitry Stogov				}
394cb9d81efSDmitry Stogov				Z_PROTECT_RECURSION_P(expr);
3956053f2a1SZeev Suraski			}
3961b29e0caSNikita Popov			print_hash(buf, Z_ARRVAL_P(expr), indent, 0);
397cb9d81efSDmitry Stogov			if (Z_REFCOUNTED_P(expr)) {
398cb9d81efSDmitry Stogov				Z_UNPROTECT_RECURSION_P(expr);
399b3b616cfSDmitry Stogov			}
400573b4602SAndi Gutmans			break;
401573b4602SAndi Gutmans		case IS_OBJECT:
402c259cb7cSAndi Gutmans			{
4038ce1211aSMarcus Boerger				HashTable *properties;
4048ce1211aSMarcus Boerger				int is_temp;
4058ce1211aSMarcus Boerger
406bdeb220fSAnatol Belski				zend_string *class_name = Z_OBJ_HANDLER_P(expr, get_class_name)(Z_OBJ_P(expr));
4071b29e0caSNikita Popov				smart_str_appends(buf, ZSTR_VAL(class_name));
408df79b9b2SNikita Popov				zend_string_release(class_name);
409df79b9b2SNikita Popov
4101b29e0caSNikita Popov				smart_str_appends(buf, " Object\n");
411cb9d81efSDmitry Stogov				if (Z_IS_RECURSIVE_P(expr)) {
412