zend.c revision ccc12b82
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
8649ea143bSDmitry Stogov#if ZEND_RC_DEBUG
8749ea143bSDmitry StogovZEND_API zend_bool zend_rc_debug = 0;
8849ea143bSDmitry Stogov#endif
8949ea143bSDmitry Stogov
90b4892511SJani Taskinenstatic ZEND_INI_MH(OnUpdateErrorReporting) /* {{{ */
914be862b0SZeev Suraski{
924be862b0SZeev Suraski	if (!new_value) {
93d3e50265SMarcus Boerger		EG(error_reporting) = E_ALL & ~E_NOTICE & ~E_STRICT & ~E_DEPRECATED;
944be862b0SZeev Suraski	} else {
957aa76271SDmitry Stogov		EG(error_reporting) = atoi(ZSTR_VAL(new_value));
964be862b0SZeev Suraski	}
974be862b0SZeev Suraski	return SUCCESS;
984be862b0SZeev Suraski}
99b4892511SJani Taskinen/* }}} */
1004be862b0SZeev Suraski
10171592cecSDmitry Stogovstatic ZEND_INI_MH(OnUpdateGCEnabled) /* {{{ */
10271592cecSDmitry Stogov{
103bdeb220fSAnatol Belski	OnUpdateBool(entry, new_value, mh_arg1, mh_arg2, mh_arg3, stage);
10471592cecSDmitry Stogov
10571592cecSDmitry Stogov	if (GC_G(gc_enabled)) {
106bdeb220fSAnatol Belski		gc_init();
10771592cecSDmitry Stogov	}
10871592cecSDmitry Stogov
10971592cecSDmitry Stogov	return SUCCESS;
11071592cecSDmitry Stogov}
11171592cecSDmitry Stogov/* }}} */
11271592cecSDmitry Stogov
113bbf3d43cSMoriyoshi Koizumistatic ZEND_INI_MH(OnUpdateScriptEncoding) /* {{{ */
114bbf3d43cSMoriyoshi Koizumi{
115e46852d2SAnatol Belski	if (!CG(multibyte)) {
116bbf3d43cSMoriyoshi Koizumi		return FAILURE;
117bbf3d43cSMoriyoshi Koizumi	}
118bdeb220fSAnatol Belski	if (!zend_multibyte_get_functions()) {
119bbf3d43cSMoriyoshi Koizumi		return SUCCESS;
120bbf3d43cSMoriyoshi Koizumi	}
1217aa76271SDmitry Stogov	return zend_multibyte_set_script_encoding_by_string(new_value ? ZSTR_VAL(new_value) : NULL, new_value ? ZSTR_LEN(new_value) : 0);
122bbf3d43cSMoriyoshi Koizumi}
123bbf3d43cSMoriyoshi Koizumi/* }}} */
124bbf3d43cSMoriyoshi Koizumi
1259a20323eSDmitry Stogovstatic ZEND_INI_MH(OnUpdateAssertions) /* {{{ */
1269a20323eSDmitry Stogov{
1279a20323eSDmitry Stogov	zend_long *p, val;
1289a20323eSDmitry Stogov#ifndef ZTS
1299a20323eSDmitry Stogov	char *base = (char *) mh_arg2;
1309a20323eSDmitry Stogov#else
1319a20323eSDmitry Stogov	char *base;
1329a20323eSDmitry Stogov
1339a20323eSDmitry Stogov	base = (char *) ts_resource(*((int *) mh_arg2));
1349a20323eSDmitry Stogov#endif
1359a20323eSDmitry Stogov
1369a20323eSDmitry Stogov	p = (zend_long *) (base+(size_t) mh_arg1);
1379a20323eSDmitry Stogov
1380d1eeeb6SAnatol Belski	val = zend_atol(ZSTR_VAL(new_value), ZSTR_LEN(new_value));
1399a20323eSDmitry Stogov
1409a20323eSDmitry Stogov	if (stage != ZEND_INI_STAGE_STARTUP &&
1419a20323eSDmitry Stogov	    stage != ZEND_INI_STAGE_SHUTDOWN &&
1429a20323eSDmitry Stogov	    *p != val &&
1439a20323eSDmitry Stogov	    (*p < 0 || val < 0)) {
1449a20323eSDmitry Stogov		zend_error(E_WARNING, "zend.assertions may be completely enabled or disabled only in php.ini");
1459a20323eSDmitry Stogov		return FAILURE;
1469a20323eSDmitry Stogov	}
1479a20323eSDmitry Stogov
1489a20323eSDmitry Stogov	*p = val;
1499a20323eSDmitry Stogov	return SUCCESS;
1509a20323eSDmitry Stogov}
1519a20323eSDmitry Stogov/* }}} */
152bbf3d43cSMoriyoshi Koizumi
1534be862b0SZeev SuraskiZEND_INI_BEGIN()
154eb6fd52eSZeev Suraski	ZEND_INI_ENTRY("error_reporting",				NULL,		ZEND_INI_ALL,		OnUpdateErrorReporting)
155fb2c890cSRasmus Lerdorf	STD_ZEND_INI_ENTRY("zend.assertions",				"1",    ZEND_INI_ALL,       OnUpdateAssertions,           assertions,   zend_executor_globals,  executor_globals)
15671592cecSDmitry Stogov	STD_ZEND_INI_BOOLEAN("zend.enable_gc",				"1",	ZEND_INI_ALL,		OnUpdateGCEnabled,      gc_enabled,     zend_gc_globals,        gc_globals)
157ab93d8c6SDmitry Stogov 	STD_ZEND_INI_BOOLEAN("zend.multibyte", "0", ZEND_INI_PERDIR, OnUpdateBool, multibyte,      zend_compiler_globals, compiler_globals)
158bbf3d43cSMoriyoshi Koizumi 	ZEND_INI_ENTRY("zend.script_encoding",			NULL,		ZEND_INI_ALL,		OnUpdateScriptEncoding)
159bbf3d43cSMoriyoshi Koizumi 	STD_ZEND_INI_BOOLEAN("zend.detect_unicode",			"1",	ZEND_INI_ALL,		OnUpdateBool, detect_unicode, zend_compiler_globals, compiler_globals)
16034d93f0cSIlia Alshanetsky#ifdef ZEND_SIGNALS
16134d93f0cSIlia Alshanetsky	STD_ZEND_INI_BOOLEAN("zend.signal_check", "0", ZEND_INI_SYSTEM, OnUpdateBool, check, zend_signal_globals_t, zend_signal_globals)
16234d93f0cSIlia Alshanetsky#endif
1634be862b0SZeev SuraskiZEND_INI_END()
1644be862b0SZeev Suraski
1655fc9aa9aSNikita PopovZEND_API size_t zend_vspprintf(char **pbuf, size_t max_len, const char *format, va_list ap) /* {{{ */
1665fc9aa9aSNikita Popov{
1675fc9aa9aSNikita Popov	smart_string buf = {0};
1685fc9aa9aSNikita Popov
1695fc9aa9aSNikita Popov	/* since there are places where (v)spprintf called without checking for null,
1705fc9aa9aSNikita Popov	   a bit of defensive coding here */
1715fc9aa9aSNikita Popov	if (!pbuf) {
1725fc9aa9aSNikita Popov		return 0;
1735fc9aa9aSNikita Popov	}
1745fc9aa9aSNikita Popov
1755fc9aa9aSNikita Popov	zend_printf_to_smart_string(&buf, format, ap);
1765fc9aa9aSNikita Popov
1775fc9aa9aSNikita Popov	if (max_len && buf.len > max_len) {
1785fc9aa9aSNikita Popov		buf.len = max_len;
1795fc9aa9aSNikita Popov	}
1805fc9aa9aSNikita Popov
1815fc9aa9aSNikita Popov	smart_string_0(&buf);
1825fc9aa9aSNikita Popov
1835fc9aa9aSNikita Popov	if (buf.c) {
1845fc9aa9aSNikita Popov		*pbuf = buf.c;
1855fc9aa9aSNikita Popov		return buf.len;
1865fc9aa9aSNikita Popov	} else {
1875fc9aa9aSNikita Popov		*pbuf = estrndup("", 0);
1885fc9aa9aSNikita Popov		return 0;
1895fc9aa9aSNikita Popov	}
1905fc9aa9aSNikita Popov}
1915fc9aa9aSNikita Popov/* }}} */
1925fc9aa9aSNikita Popov
193c7742e28SNikita PopovZEND_API size_t zend_spprintf(char **message, size_t max_len, const char *format, ...) /* {{{ */
194c7742e28SNikita Popov{
195c7742e28SNikita Popov	va_list arg;
196c7742e28SNikita Popov	size_t len;
197c7742e28SNikita Popov
198c7742e28SNikita Popov	va_start(arg, format);
199c7742e28SNikita Popov	len = zend_vspprintf(message, max_len, format, arg);
200c7742e28SNikita Popov	va_end(arg);
201c7742e28SNikita Popov	return len;
202c7742e28SNikita Popov}
203c7742e28SNikita Popov/* }}} */
204c7742e28SNikita Popov
2055fc9aa9aSNikita PopovZEND_API zend_string *zend_vstrpprintf(size_t max_len, const char *format, va_list ap) /* {{{ */
2065fc9aa9aSNikita Popov{
2075fc9aa9aSNikita Popov	smart_str buf = {0};
2085fc9aa9aSNikita Popov
2095fc9aa9aSNikita Popov	zend_printf_to_smart_str(&buf, format, ap);
2105fc9aa9aSNikita Popov
2115fc9aa9aSNikita Popov	if (!buf.s) {
2125fc9aa9aSNikita Popov		return ZSTR_EMPTY_ALLOC();
2135fc9aa9aSNikita Popov	}
2145fc9aa9aSNikita Popov
2155fc9aa9aSNikita Popov	if (max_len && ZSTR_LEN(buf.s) > max_len) {
2165fc9aa9aSNikita Popov		ZSTR_LEN(buf.s) = max_len;
2175fc9aa9aSNikita Popov	}
2185fc9aa9aSNikita Popov
2195fc9aa9aSNikita Popov	smart_str_0(&buf);
2205fc9aa9aSNikita Popov	return buf.s;
2215fc9aa9aSNikita Popov}
2225fc9aa9aSNikita Popov/* }}} */
2235fc9aa9aSNikita Popov
224c7742e28SNikita PopovZEND_API zend_string *zend_strpprintf(size_t max_len, const char *format, ...) /* {{{ */
225c7742e28SNikita Popov{
226c7742e28SNikita Popov	va_list arg;
227c7742e28SNikita Popov	zend_string *str;
228c7742e28SNikita Popov
229c7742e28SNikita Popov	va_start(arg, format);
230c7742e28SNikita Popov	str = zend_vstrpprintf(max_len, format, arg);
231c7742e28SNikita Popov	va_end(arg);
232c7742e28SNikita Popov	return str;
233c7742e28SNikita Popov}
234c7742e28SNikita Popov/* }}} */
235c7742e28SNikita Popov
2361b29e0caSNikita Popovstatic void zend_print_zval_r_to_buf(smart_str *buf, zval *expr, int indent);
2371b29e0caSNikita Popov
2381b29e0caSNikita Popovstatic void print_hash(smart_str *buf, HashTable *ht, int indent, zend_bool is_object) /* {{{ */
239573b4602SAndi Gutmans{
240f4cfaf36SDmitry Stogov	zval *tmp;
241f4cfaf36SDmitry Stogov	zend_string *string_key;
242c3e3c98eSAnatol Belski	zend_ulong num_key;
243573b4602SAndi Gutmans	int i;
244573b4602SAndi Gutmans
245b4892511SJani Taskinen	for (i = 0; i < indent; i++) {
2461b29e0caSNikita Popov		smart_str_appendc(buf, ' ');
247573b4602SAndi Gutmans	}
2481b29e0caSNikita Popov	smart_str_appends(buf, "(\n");
24980bab9d9SAndrei Zmievski	indent += PRINT_ZVAL_INDENT;
2501b29e0caSNikita Popov	ZEND_HASH_FOREACH_KEY_VAL_IND(ht, num_key, string_key, tmp) {
251b4892511SJani Taskinen		for (i = 0; i < indent; i++) {
2521b29e0caSNikita Popov			smart_str_appendc(buf, ' ');
253573b4602SAndi Gutmans		}
2541b29e0caSNikita Popov		smart_str_appendc(buf, '[');
2557652a977SDmitry Stogov		if (string_key) {
2567652a977SDmitry Stogov			if (is_object) {
2577652a977SDmitry Stogov				const char *prop_name, *class_name;
258079409bbSNikita Popov				size_t prop_len;
259079409bbSNikita Popov				int mangled = zend_unmangle_property_name_ex(string_key, &class_name, &prop_name, &prop_len);
2607652a977SDmitry Stogov
2611b29e0caSNikita Popov				smart_str_appendl(buf, prop_name, prop_len);
2627652a977SDmitry Stogov				if (class_name && mangled == SUCCESS) {
2631b29e0caSNikita Popov					if (class_name[0] == '*') {
2641b29e0caSNikita Popov						smart_str_appends(buf, ":protected");
2657652a977SDmitry Stogov					} else {
2661b29e0caSNikita Popov						smart_str_appends(buf, ":");
2671b29e0caSNikita Popov						smart_str_appends(buf, class_name);
2681b29e0caSNikita Popov						smart_str_appends(buf, ":private");
269d329ce93SZeev Suraski					}
270d3d02fbcSDmitry Stogov				}
2717652a977SDmitry Stogov			} else {
2721b29e0caSNikita Popov				smart_str_append(buf, string_key);
2737652a977SDmitry Stogov			}
2747652a977SDmitry Stogov		} else {
2751b29e0caSNikita Popov			smart_str_append_long(buf, num_key);
276573b4602SAndi Gutmans		}
2771b29e0caSNikita Popov		smart_str_appends(buf, "] => ");
2781b29e0caSNikita Popov		zend_print_zval_r_to_buf(buf, tmp, indent+PRINT_ZVAL_INDENT);
2791b29e0caSNikita Popov		smart_str_appends(buf, "\n");
2807652a977SDmitry Stogov	} ZEND_HASH_FOREACH_END();
28180bab9d9SAndrei Zmievski	indent -= PRINT_ZVAL_INDENT;
282b4892511SJani Taskinen	for (i = 0; i < indent; i++) {
2831b29e0caSNikita Popov		smart_str_appendc(buf, ' ');
284573b4602SAndi Gutmans	}
2851b29e0caSNikita Popov	smart_str_appends(buf, ")\n");
286573b4602SAndi Gutmans}
287b4892511SJani Taskinen/* }}} */
288573b4602SAndi Gutmans
289bdeb220fSAnatol Belskistatic void print_flat_hash(HashTable *ht) /* {{{ */
29027de54b0SAndi Gutmans{
291f4cfaf36SDmitry Stogov	zval *tmp;
292f4cfaf36SDmitry Stogov	zend_string *string_key;
293c3e3c98eSAnatol Belski	zend_ulong num_key;
294b4892511SJani Taskinen	int i = 0;
295b4892511SJani Taskinen
2960ade00c8SNikita Popov	ZEND_HASH_FOREACH_KEY_VAL_IND(ht, num_key, string_key, tmp) {
297b4892511SJani Taskinen		if (i++ > 0) {
298b4892511SJani Taskinen			ZEND_PUTS(",");
299b4892511SJani Taskinen		}
300b4892511SJani Taskinen		ZEND_PUTS("[");
3017652a977SDmitry Stogov		if (string_key) {
3027aa76271SDmitry Stogov			ZEND_WRITE(ZSTR_VAL(string_key), ZSTR_LEN(string_key));
3037652a977SDmitry Stogov		} else {
3044d997f63SAnatol Belski			zend_printf(ZEND_ULONG_FMT, num_key);
305b4892511SJani Taskinen		}
306b4892511SJani Taskinen		ZEND_PUTS("] => ");
307bdeb220fSAnatol Belski		zend_print_flat_zval_r(tmp);
3087652a977SDmitry Stogov	} ZEND_HASH_FOREACH_END();
30927de54b0SAndi Gutmans}
310b4892511SJani Taskinen/* }}} */
3117a87fcbbSZeev Suraski
312bdeb220fSAnatol BelskiZEND_API int zend_make_printable_zval(zval *expr, zval *expr_copy) /* {{{ */
313573b4602SAndi Gutmans{
314f3a6c30cSXinchen Hui	if (Z_TYPE_P(expr) == IS_STRING) {
3159d6e45a0SDmitry Stogov		return 0;
31622fbfdfbSXinchen Hui	} else {
317ce18738aSDmitry Stogov		ZVAL_STR(expr_copy, zval_get_string_func(expr));
31822fbfdfbSXinchen Hui		return 1;
319da9faa2cSZeev Suraski	}
320da9faa2cSZeev Suraski}
321b4892511SJani Taskinen/* }}} */
322da9faa2cSZeev Suraski
323bdeb220fSAnatol BelskiZEND_API size_t zend_print_zval(zval *expr, int indent) /* {{{ */
324da9faa2cSZeev Suraski{
325ccc12b82SDmitry Stogov	zend_string *tmp_str;
326ccc12b82SDmitry Stogov	zend_string *str = zval_get_tmp_string(expr, &tmp_str);
3277aa76271SDmitry Stogov	size_t len = ZSTR_LEN(str);
328da9faa2cSZeev Suraski
329bda96e3cSNikita Popov	if (len != 0) {
3301b29e0caSNikita Popov		zend_write(ZSTR_VAL(str), len);
331573b4602SAndi Gutmans	}
332bda96e3cSNikita Popov
333ccc12b82SDmitry Stogov	zend_tmp_string_release(tmp_str);
334bda96e3cSNikita Popov	return len;
335573b4602SAndi Gutmans}
336b4892511SJani Taskinen/* }}} */
337573b4602SAndi Gutmans
338bdeb220fSAnatol BelskiZEND_API void zend_print_flat_zval_r(zval *expr) /* {{{ */
33927de54b0SAndi Gutmans{
340b4892511SJani Taskinen	switch (Z_TYPE_P(expr)) {
341b4892511SJani Taskinen		case IS_ARRAY:
342b4892511SJani Taskinen			ZEND_PUTS("Array (");
343cb9d81efSDmitry Stogov			if (Z_REFCOUNTED_P(expr)) {
344cb9d81efSDmitry Stogov				if (Z_IS_RECURSIVE_P(expr)) {
345cb9d81efSDmitry Stogov					ZEND_PUTS(" *RECURSION*");
346cb9d81efSDmitry Stogov					return;
347cb9d81efSDmitry Stogov				}
348cb9d81efSDmitry Stogov				Z_PROTECT_RECURSION_P(expr);
349b4892511SJani Taskinen			}
350bdeb220fSAnatol Belski			print_flat_hash(Z_ARRVAL_P(expr));
351b4892511SJani Taskinen			ZEND_PUTS(")");
352cb9d81efSDmitry Stogov			if (Z_REFCOUNTED_P(expr)) {
353cb9d81efSDmitry Stogov				Z_UNPROTECT_RECURSION_P(expr);
354b3b616cfSDmitry Stogov			}
355b4892511SJani Taskinen			break;
356b4892511SJani Taskinen		case IS_OBJECT:
357b4892511SJani Taskinen		{
3589bba373aSStanislav Malyshev			HashTable *properties = NULL;
359bdeb220fSAnatol Belski			zend_string *class_name = Z_OBJ_HANDLER_P(expr, get_class_name)(Z_OBJ_P(expr));
3607aa76271SDmitry Stogov			zend_printf("%s Object (", ZSTR_VAL(class_name));
361df79b9b2SNikita Popov			zend_string_release(class_name);
3628ce1211aSMarcus Boerger
363cb9d81efSDmitry Stogov			if (Z_IS_RECURSIVE_P(expr)) {
364dc764bf6SNikita Popov				ZEND_PUTS(" *RECURSION*");
365dc764bf6SNikita Popov				return;
366dc764bf6SNikita Popov			}
367dc764bf6SNikita Popov
368f30f3590SStanislav Malyshev			if (Z_OBJ_HANDLER_P(expr, get_properties)) {
3699bba373aSStanislav Malyshev				properties = Z_OBJPROP_P(expr);
3709bba373aSStanislav Malyshev			}
371f30f3590SStanislav Malyshev			if (properties) {
372cb9d81efSDmitry Stogov				Z_PROTECT_RECURSION_P(expr);
373bdeb220fSAnatol Belski				print_flat_hash(properties);
374cb9d81efSDmitry Stogov				Z_UNPROTECT_RECURSION_P(expr);
3759bba373aSStanislav Malyshev			}
3769bba373aSStanislav Malyshev			ZEND_PUTS(")");
3779bba373aSStanislav Malyshev			break;
378b4892511SJani Taskinen		}
379b0037688SBob Weinand		case IS_REFERENCE:
380b0037688SBob Weinand			zend_print_flat_zval_r(Z_REFVAL_P(expr));
381b0037688SBob Weinand			break;
382b4892511SJani Taskinen		default:
383bdeb220fSAnatol Belski			zend_print_variable(expr);
384b4892511SJani Taskinen			break;
385b4892511SJani Taskinen	}
38627de54b0SAndi Gutmans}
387b4892511SJani Taskinen/* }}} */
388573b4602SAndi Gutmans
3891b29e0caSNikita Popovstatic void zend_print_zval_r_to_buf(smart_str *buf, zval *expr, int indent) /* {{{ */
390573b4602SAndi Gutmans{
391b4892511SJani Taskinen	switch (Z_TYPE_P(expr)) {
392573b4602SAndi Gutmans		case IS_ARRAY:
3931b29e0caSNikita Popov			smart_str_appends(buf, "Array\n");
394cb9d81efSDmitry Stogov			if (Z_REFCOUNTED_P(expr)) {
395cb9d81efSDmitry Stogov				if (Z_IS_RECURSIVE_P(expr)) {
396cb9d81efSDmitry Stogov					smart_str_appends(buf, " *RECURSION*");
397cb9d81efSDmitry Stogov					return;
398cb9d81efSDmitry Stogov				}
399cb9d81efSDmitry Stogov				Z_PROTECT_RECURSION_P(expr);
4006053f2a1SZeev Suraski			}
4011b29e0caSNikita Popov			print_hash(buf, Z_ARRVAL_P(expr), indent, 0);
402cb9d81efSDmitry Stogov			if (Z_REFCOUNTED_P(expr)) {
403cb9d81efSDmitry Stogov				Z_UNPROTECT_RECURSION_P(expr);
404b3b616cfSDmitry Stogov			}
405573b4602SAndi Gutmans			break;
406573b4602SAndi Gutmans		case IS_OBJECT:
407c259cb7cSAndi Gutmans			{
4088ce1211aSMarcus Boerger				HashTable *properties;
4098ce1211aSMarcus Boerger				int is_temp;
4108ce1211aSMarcus Boerger
411bdeb220fSAnatol Belski				zend_string *class_name = Z_OBJ_HANDLER_P(expr, get_class_name)(Z_OBJ_P(expr));
4121b29e0caSNikita Popov				smart_str_appends(buf, ZSTR_VAL(class_name));
413