zend.c revision bbf3d43c
1573b4602SAndi Gutmans/*
2573b4602SAndi Gutmans   +----------------------------------------------------------------------+
3573b4602SAndi Gutmans   | Zend Engine                                                          |
4573b4602SAndi Gutmans   +----------------------------------------------------------------------+
5d2281d1dSSebastian Bergmann   | Copyright (c) 1998-2010 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"
33573b4602SAndi Gutmans
347a87fcbbSZeev Suraski#ifdef ZTS
35b4892511SJani Taskinen# define GLOBAL_FUNCTION_TABLE		global_function_table
36b4892511SJani Taskinen# define GLOBAL_CLASS_TABLE			global_class_table
37b4892511SJani Taskinen# define GLOBAL_CONSTANTS_TABLE		global_constants_table
38b4892511SJani Taskinen# define GLOBAL_AUTO_GLOBALS_TABLE	global_auto_globals_table
397a87fcbbSZeev Suraski#else
40b4892511SJani Taskinen# define GLOBAL_FUNCTION_TABLE		CG(function_table)
41b4892511SJani Taskinen# define GLOBAL_CLASS_TABLE			CG(class_table)
42b4892511SJani Taskinen# define GLOBAL_AUTO_GLOBALS_TABLE	CG(auto_globals)
43b4892511SJani Taskinen# define GLOBAL_CONSTANTS_TABLE		EG(zend_constants)
447a87fcbbSZeev Suraski#endif
457a87fcbbSZeev Suraski
46f34b9d41SZeev Suraski#if defined(ZEND_WIN32) && ZEND_DEBUG
472ffe85ddSZeev SuraskiBOOL WINAPI IsDebuggerPresent(VOID);
482ffe85ddSZeev Suraski#endif
492ffe85ddSZeev Suraski
50573b4602SAndi Gutmans/* true multithread-shared globals */
5192dd5e61SStanislav MalyshevZEND_API zend_class_entry *zend_standard_class_def = NULL;
52573b4602SAndi GutmansZEND_API int (*zend_printf)(const char *format, ...);
535dba4774SZeev SuraskiZEND_API zend_write_func_t zend_write;
5485ab4235SFelipe PenaZEND_API FILE *(*zend_fopen)(const char *filename, char **opened_path TSRMLS_DC);
55e52aac94SWez FurlongZEND_API int (*zend_stream_open_function)(const char *filename, zend_file_handle *handle TSRMLS_DC);
5693536507SStig S. BakkenZEND_API void (*zend_block_interruptions)(void);
5793536507SStig S. BakkenZEND_API void (*zend_unblock_interruptions)(void);
58f1a2ee55SAndi GutmansZEND_API void (*zend_ticks_function)(int ticks);
59536221beSStanislav MalyshevZEND_API void (*zend_error_cb)(int type, const char *error_filename, const uint error_lineno, const char *format, va_list args);
60d45fd8a1SMarcus Boergerint (*zend_vspprintf)(char **pbuf, size_t max_len, const char *format, va_list ap);
6185a36e2bSZeev SuraskiZEND_API char *(*zend_getenv)(char *name, size_t name_len TSRMLS_DC);
62ab232458SDmitry StogovZEND_API char *(*zend_resolve_path)(const char *filename, int filename_len TSRMLS_DC);
63536221beSStanislav Malyshev
64bd115087SZeev Suraskivoid (*zend_on_timeout)(int seconds TSRMLS_DC);
65bd115087SZeev Suraski
6685ab4235SFelipe Penastatic void (*zend_message_dispatcher_p)(long message, void *data TSRMLS_DC);
67cf7384aaSFelipe Penastatic int (*zend_get_configuration_directive_p)(const char *name, uint name_length, zval *contents);
68d035af4aSZeev Suraski
69b4892511SJani Taskinenstatic ZEND_INI_MH(OnUpdateErrorReporting) /* {{{ */
704be862b0SZeev Suraski{
714be862b0SZeev Suraski	if (!new_value) {
72d3e50265SMarcus Boerger		EG(error_reporting) = E_ALL & ~E_NOTICE & ~E_STRICT & ~E_DEPRECATED;
734be862b0SZeev Suraski	} else {
744be862b0SZeev Suraski		EG(error_reporting) = atoi(new_value);
754be862b0SZeev Suraski	}
764be862b0SZeev Suraski	return SUCCESS;
774be862b0SZeev Suraski}
78b4892511SJani Taskinen/* }}} */
794be862b0SZeev Suraski
8071592cecSDmitry Stogovstatic ZEND_INI_MH(OnUpdateGCEnabled) /* {{{ */
8171592cecSDmitry Stogov{
8271592cecSDmitry Stogov	OnUpdateBool(entry, new_value, new_value_length, mh_arg1, mh_arg2, mh_arg3, stage TSRMLS_CC);
8371592cecSDmitry Stogov
8471592cecSDmitry Stogov	if (GC_G(gc_enabled)) {
8571592cecSDmitry Stogov		gc_init(TSRMLS_C);
8671592cecSDmitry Stogov	}
8771592cecSDmitry Stogov
8871592cecSDmitry Stogov	return SUCCESS;
8971592cecSDmitry Stogov}
9071592cecSDmitry Stogov/* }}} */
9171592cecSDmitry Stogov
92bbf3d43cSMoriyoshi Koizumistatic ZEND_INI_MH(OnUpdateScriptEncoding) /* {{{ */
93bbf3d43cSMoriyoshi Koizumi{
94bbf3d43cSMoriyoshi Koizumi	if (!CG(multibyte)) {
95bbf3d43cSMoriyoshi Koizumi		return FAILURE;
96bbf3d43cSMoriyoshi Koizumi	}
97bbf3d43cSMoriyoshi Koizumi	if (!zend_multibyte_get_functions(TSRMLS_C)) {
98bbf3d43cSMoriyoshi Koizumi		return SUCCESS;
99bbf3d43cSMoriyoshi Koizumi	}
100bbf3d43cSMoriyoshi Koizumi	return zend_multibyte_set_script_encoding_by_string(new_value, new_value_length TSRMLS_CC);
101bbf3d43cSMoriyoshi Koizumi}
102bbf3d43cSMoriyoshi Koizumi/* }}} */
103bbf3d43cSMoriyoshi Koizumi
104bbf3d43cSMoriyoshi Koizumi
1054be862b0SZeev SuraskiZEND_INI_BEGIN()
106eb6fd52eSZeev Suraski	ZEND_INI_ENTRY("error_reporting",				NULL,		ZEND_INI_ALL,		OnUpdateErrorReporting)
10771592cecSDmitry Stogov	STD_ZEND_INI_BOOLEAN("zend.enable_gc",				"1",	ZEND_INI_ALL,		OnUpdateGCEnabled,      gc_enabled,     zend_gc_globals,        gc_globals)
108ab93d8c6SDmitry Stogov 	STD_ZEND_INI_BOOLEAN("zend.multibyte", "0", ZEND_INI_PERDIR, OnUpdateBool, multibyte,      zend_compiler_globals, compiler_globals)
109bbf3d43cSMoriyoshi Koizumi 	ZEND_INI_ENTRY("zend.script_encoding",			NULL,		ZEND_INI_ALL,		OnUpdateScriptEncoding)
110bbf3d43cSMoriyoshi Koizumi 	STD_ZEND_INI_BOOLEAN("zend.detect_unicode",			"1",	ZEND_INI_ALL,		OnUpdateBool, detect_unicode, zend_compiler_globals, compiler_globals)
1114be862b0SZeev SuraskiZEND_INI_END()
1124be862b0SZeev Suraski
1134be862b0SZeev Suraski
1147a87fcbbSZeev Suraski#ifdef ZTS
115e06a1ed2SZeev SuraskiZEND_API int compiler_globals_id;
116e06a1ed2SZeev SuraskiZEND_API int executor_globals_id;
117b4892511SJani Taskinenstatic HashTable *global_function_table = NULL;
118b4892511SJani Taskinenstatic HashTable *global_class_table = NULL;
119b4892511SJani Taskinenstatic HashTable *global_constants_table = NULL;
120b4892511SJani Taskinenstatic HashTable *global_auto_globals_table = NULL;
12121698c12SDmitry Stogovstatic HashTable *global_persistent_list = NULL;
1227a87fcbbSZeev Suraski#endif
123573b4602SAndi Gutmans
124e801a99aSZeev SuraskiZEND_API zend_utility_values zend_uv;
125573b4602SAndi Gutmans
1265ba5f00fSZeev SuraskiZEND_API zval zval_used_for_init; /* True global variable */
127213d0e2fSAndi Gutmans
128573b4602SAndi Gutmans/* version information */
129573b4602SAndi Gutmansstatic char *zend_version_info;
130573b4602SAndi Gutmansstatic uint zend_version_info_length;
131d2281d1dSSebastian Bergmann#define ZEND_CORE_VERSION_INFO	"Zend Engine v" ZEND_VERSION ", Copyright (c) 1998-2010 Zend Technologies\n"
13280bab9d9SAndrei Zmievski#define PRINT_ZVAL_INDENT 4
133573b4602SAndi Gutmans
134d3d02fbcSDmitry Stogovstatic void print_hash(zend_write_func_t write_func, HashTable *ht, int indent, zend_bool is_object TSRMLS_DC) /* {{{ */
135573b4602SAndi Gutmans{
136573b4602SAndi Gutmans	zval **tmp;
137573b4602SAndi Gutmans	char *string_key;
13863873abaSStanislav Malyshev	HashPosition iterator;
1394757104eSZeev Suraski	ulong num_key;
1404757104eSZeev Suraski	uint str_len;
141573b4602SAndi Gutmans	int i;
142573b4602SAndi Gutmans
143b4892511SJani Taskinen	for (i = 0; i < indent; i++) {
144d3d02fbcSDmitry Stogov		ZEND_PUTS_EX(" ");
145573b4602SAndi Gutmans	}
146d3d02fbcSDmitry Stogov	ZEND_PUTS_EX("(\n");
14780bab9d9SAndrei Zmievski	indent += PRINT_ZVAL_INDENT;
14863873abaSStanislav Malyshev	zend_hash_internal_pointer_reset_ex(ht, &iterator);
14963873abaSStanislav Malyshev	while (zend_hash_get_current_data_ex(ht, (void **) &tmp, &iterator) == SUCCESS) {
150b4892511SJani Taskinen		for (i = 0; i < indent; i++) {
151d3d02fbcSDmitry Stogov			ZEND_PUTS_EX(" ");
152573b4602SAndi Gutmans		}
153d3d02fbcSDmitry Stogov		ZEND_PUTS_EX("[");
15436eaad25SZeev Suraski		switch (zend_hash_get_current_key_ex(ht, &string_key, &str_len, &num_key, 0, &iterator)) {
155573b4602SAndi Gutmans			case HASH_KEY_IS_STRING:
156d329ce93SZeev Suraski				if (is_object) {
157d329ce93SZeev Suraski					char *prop_name, *class_name;
158b4892511SJani Taskinen					int mangled = zend_unmangle_property_name(string_key, str_len - 1, &class_name, &prop_name);
159d329ce93SZeev Suraski
160d3d02fbcSDmitry Stogov					ZEND_PUTS_EX(prop_name);
161978dd0fdSMarcus Boerger					if (class_name && mangled == SUCCESS) {
162d329ce93SZeev Suraski						if (class_name[0]=='*') {
163d3d02fbcSDmitry Stogov							ZEND_PUTS_EX(":protected");
164d329ce93SZeev Suraski						} else {
165d3d02fbcSDmitry Stogov							ZEND_PUTS_EX(":");
166d3d02fbcSDmitry Stogov							ZEND_PUTS_EX(class_name);
167d3d02fbcSDmitry Stogov							ZEND_PUTS_EX(":private");
168d329ce93SZeev Suraski						}
169d329ce93SZeev Suraski					}
170d329ce93SZeev Suraski				} else {
171d3d02fbcSDmitry Stogov					ZEND_WRITE_EX(string_key, str_len-1);
172d329ce93SZeev Suraski				}
173573b4602SAndi Gutmans				break;
174573b4602SAndi Gutmans			case HASH_KEY_IS_LONG:
175d3d02fbcSDmitry Stogov				{
176d3d02fbcSDmitry Stogov					char key[25];
177d3d02fbcSDmitry Stogov					snprintf(key, sizeof(key), "%ld", num_key);
178d3d02fbcSDmitry Stogov					ZEND_PUTS_EX(key);
179d3d02fbcSDmitry Stogov				}
180573b4602SAndi Gutmans				break;
181573b4602SAndi Gutmans		}
182d3d02fbcSDmitry Stogov		ZEND_PUTS_EX("] => ");
183d3d02fbcSDmitry Stogov		zend_print_zval_r_ex(write_func, *tmp, indent+PRINT_ZVAL_INDENT TSRMLS_CC);
184d3d02fbcSDmitry Stogov		ZEND_PUTS_EX("\n");
18563873abaSStanislav Malyshev		zend_hash_move_forward_ex(ht, &iterator);
186573b4602SAndi Gutmans	}
18780bab9d9SAndrei Zmievski	indent -= PRINT_ZVAL_INDENT;
188b4892511SJani Taskinen	for (i = 0; i < indent; i++) {
189d3d02fbcSDmitry Stogov		ZEND_PUTS_EX(" ");
190573b4602SAndi Gutmans	}
191d3d02fbcSDmitry Stogov	ZEND_PUTS_EX(")\n");
192573b4602SAndi Gutmans}
193b4892511SJani Taskinen/* }}} */
194573b4602SAndi Gutmans
195b4892511SJani Taskinenstatic void print_flat_hash(HashTable *ht TSRMLS_DC) /* {{{ */
19627de54b0SAndi Gutmans{
197b4892511SJani Taskinen	zval **tmp;
198b4892511SJani Taskinen	char *string_key;
199b4892511SJani Taskinen	HashPosition iterator;
200b4892511SJani Taskinen	ulong num_key;
201b4892511SJani Taskinen	uint str_len;
202b4892511SJani Taskinen	int i = 0;
203b4892511SJani Taskinen
204b4892511SJani Taskinen	zend_hash_internal_pointer_reset_ex(ht, &iterator);
205b4892511SJani Taskinen	while (zend_hash_get_current_data_ex(ht, (void **) &tmp, &iterator) == SUCCESS) {
206b4892511SJani Taskinen		if (i++ > 0) {
207b4892511SJani Taskinen			ZEND_PUTS(",");
208b4892511SJani Taskinen		}
209b4892511SJani Taskinen		ZEND_PUTS("[");
210b4892511SJani Taskinen		switch (zend_hash_get_current_key_ex(ht, &string_key, &str_len, &num_key, 0, &iterator)) {
211b4892511SJani Taskinen			case HASH_KEY_IS_STRING:
212b4892511SJani Taskinen				ZEND_PUTS(string_key);
213b4892511SJani Taskinen				break;
214b4892511SJani Taskinen			case HASH_KEY_IS_LONG:
215b4892511SJani Taskinen				zend_printf("%ld", num_key);
216b4892511SJani Taskinen				break;
217b4892511SJani Taskinen		}
218b4892511SJani Taskinen		ZEND_PUTS("] => ");
219b4892511SJani Taskinen		zend_print_flat_zval_r(*tmp TSRMLS_CC);
220b4892511SJani Taskinen		zend_hash_move_forward_ex(ht, &iterator);
22127de54b0SAndi Gutmans	}
22227de54b0SAndi Gutmans}
223b4892511SJani Taskinen/* }}} */
2247a87fcbbSZeev Suraski
225b4892511SJani TaskinenZEND_API void zend_make_printable_zval(zval *expr, zval *expr_copy, int *use_copy) /* {{{ */
226573b4602SAndi Gutmans{
227b4892511SJani Taskinen	if (Z_TYPE_P(expr)==IS_STRING) {
228da9faa2cSZeev Suraski		*use_copy = 0;
229da9faa2cSZeev Suraski		return;
230da9faa2cSZeev Suraski	}
231b4892511SJani Taskinen	switch (Z_TYPE_P(expr)) {
232bdefd5daSAndi Gutmans		case IS_NULL:
233b4892511SJani Taskinen			Z_STRLEN_P(expr_copy) = 0;
234b4892511SJani Taskinen			Z_STRVAL_P(expr_copy) = STR_EMPTY_ALLOC();
2358c4ab98eSThies C. Arntzen			break;
236da9faa2cSZeev Suraski		case IS_BOOL:
237b4892511SJani Taskinen			if (Z_LVAL_P(expr)) {
238b4892511SJani Taskinen				Z_STRLEN_P(expr_copy) = 1;
239b4892511SJani Taskinen				Z_STRVAL_P(expr_copy) = estrndup("1", 1);
24091d7ba76SAndi Gutmans			} else {
241b4892511SJani Taskinen				Z_STRLEN_P(expr_copy) = 0;
242b4892511SJani Taskinen				Z_STRVAL_P(expr_copy) = STR_EMPTY_ALLOC();
24391d7ba76SAndi Gutmans			}
244da9faa2cSZeev Suraski			break;
245da9faa2cSZeev Suraski		case IS_RESOURCE:
246b4892511SJani Taskinen			Z_STRVAL_P(expr_copy) = (char *) emalloc(sizeof("Resource id #") - 1 + MAX_LENGTH_OF_LONG);
247b4892511SJani Taskinen			Z_STRLEN_P(expr_copy) = sprintf(Z_STRVAL_P(expr_copy), "Resource id #%ld", Z_LVAL_P(expr));
248da9faa2cSZeev Suraski			break;
249da9faa2cSZeev Suraski		case IS_ARRAY:
250b4892511SJani Taskinen			Z_STRLEN_P(expr_copy) = sizeof("Array") - 1;
251b4892511SJani Taskinen			Z_STRVAL_P(expr_copy) = estrndup("Array", Z_STRLEN_P(expr_copy));
252da9faa2cSZeev Suraski			break;
2531b282b35SAndi Gutmans		case IS_OBJECT:
2547901a221SAndi Gutmans			{
255ae2bfb78SSterling Hughes				TSRMLS_FETCH();
256637a4042SMarcus Boerger
257b4892511SJani Taskinen				if (Z_OBJ_HANDLER_P(expr, cast_object) && Z_OBJ_HANDLER_P(expr, cast_object)(expr, expr_copy, IS_STRING TSRMLS_CC) == SUCCESS) {
258848c5c76SMarcus Boerger					break;
259848c5c76SMarcus Boerger				}
26088de69b9SAndi Gutmans				/* Standard PHP objects */
261b3c3c6deSMarcus Boerger				if (Z_OBJ_HT_P(expr) == &std_object_handlers || !Z_OBJ_HANDLER_P(expr, cast_object)) {
262637a4042SMarcus Boerger					if (zend_std_cast_object_tostring(expr, expr_copy, IS_STRING TSRMLS_CC) == SUCCESS) {
263d4f64f88SMarcus Boerger						break;
264d4f64f88SMarcus Boerger					}
265b3c3c6deSMarcus Boerger				}
266b3c3c6deSMarcus Boerger				if (!Z_OBJ_HANDLER_P(expr, cast_object) && Z_OBJ_HANDLER_P(expr, get)) {
267b3c3c6deSMarcus Boerger					zval *z = Z_OBJ_HANDLER_P(expr, get)(expr TSRMLS_CC);
2687addae50SMarcus Boerger
2694b4d634cSYiduo (David) Wang					Z_ADDREF_P(z);
270b4892511SJani Taskinen					if (Z_TYPE_P(z) != IS_OBJECT) {
271b3c3c6deSMarcus Boerger						zend_make_printable_zval(z, expr_copy, use_copy);
272b3c3c6deSMarcus Boerger						if (*use_copy) {
273b3c3c6deSMarcus Boerger							zval_ptr_dtor(&z);
274b3c3c6deSMarcus Boerger						} else {
275b3c3c6deSMarcus Boerger							ZVAL_ZVAL(expr_copy, z, 0, 1);
276b3c3c6deSMarcus Boerger							*use_copy = 1;
2773b8b43a9SStanislav Malyshev						}
278b3c3c6deSMarcus Boerger						return;
2793b8b43a9SStanislav Malyshev					}
280b3c3c6deSMarcus Boerger					zval_ptr_dtor(&z);
28171ba4427SMarcus Boerger				}
282d76c5161SMarcus Boerger				zend_error(EG(exception) ? E_ERROR : E_RECOVERABLE_ERROR, "Object of class %s could not be converted to string", Z_OBJCE_P(expr)->name);
283b4892511SJani Taskinen				Z_STRLEN_P(expr_copy) = 0;
284b4892511SJani Taskinen				Z_STRVAL_P(expr_copy) = STR_EMPTY_ALLOC();
285ae2bfb78SSterling Hughes			}
286da9faa2cSZeev Suraski			break;
287e842ef9fSIlia Alshanetsky		case IS_DOUBLE:
288e842ef9fSIlia Alshanetsky			*expr_copy = *expr;
289e842ef9fSIlia Alshanetsky			zval_copy_ctor(expr_copy);
290e842ef9fSIlia Alshanetsky			zend_locale_sprintf_double(expr_copy ZEND_FILE_LINE_CC);
291e842ef9fSIlia Alshanetsky			break;
292da9faa2cSZeev Suraski		default:
293da9faa2cSZeev Suraski			*expr_copy = *expr;
294da9faa2cSZeev Suraski			zval_copy_ctor(expr_copy);
295da9faa2cSZeev Suraski			convert_to_string(expr_copy);
296da9faa2cSZeev Suraski			break;
297da9faa2cSZeev Suraski	}
298b4892511SJani Taskinen	Z_TYPE_P(expr_copy) = IS_STRING;
299da9faa2cSZeev Suraski	*use_copy = 1;
300da9faa2cSZeev Suraski}
301b4892511SJani Taskinen/* }}} */
302da9faa2cSZeev Suraski
303b4892511SJani TaskinenZEND_API int zend_print_zval(zval *expr, int indent) /* {{{ */
304da9faa2cSZeev Suraski{
3055dba4774SZeev Suraski	return zend_print_zval_ex(zend_write, expr, indent);
3065dba4774SZeev Suraski}
307b4892511SJani Taskinen/* }}} */
3085dba4774SZeev Suraski
309b4892511SJani TaskinenZEND_API int zend_print_zval_ex(zend_write_func_t write_func, zval *expr, int indent) /* {{{ */
3105dba4774SZeev Suraski{
311da9faa2cSZeev Suraski	zval expr_copy;
312da9faa2cSZeev Suraski	int use_copy;
313da9faa2cSZeev Suraski
314da9faa2cSZeev Suraski	zend_make_printable_zval(expr, &expr_copy, &use_copy);
315da9faa2cSZeev Suraski	if (use_copy) {
316573b4602SAndi Gutmans		expr = &expr_copy;
317573b4602SAndi Gutmans	}
318b4892511SJani Taskinen	if (Z_STRLEN_P(expr) == 0) { /* optimize away empty strings */
319da9faa2cSZeev Suraski		if (use_copy) {
320da9faa2cSZeev Suraski			zval_dtor(expr);
321da9faa2cSZeev Suraski		}
322573b4602SAndi Gutmans		return 0;
323573b4602SAndi Gutmans	}
324b4892511SJani Taskinen	write_func(Z_STRVAL_P(expr), Z_STRLEN_P(expr));
325da9faa2cSZeev Suraski	if (use_copy) {
326573b4602SAndi Gutmans		zval_dtor(expr);
327573b4602SAndi Gutmans	}
328b4892511SJani Taskinen	return Z_STRLEN_P(expr);
329573b4602SAndi Gutmans}
330b4892511SJani Taskinen/* }}} */
331573b4602SAndi Gutmans
332b4892511SJani TaskinenZEND_API void zend_print_flat_zval_r(zval *expr TSRMLS_DC) /* {{{ */
33327de54b0SAndi Gutmans{
334b4892511SJani Taskinen	switch (Z_TYPE_P(expr)) {
335b4892511SJani Taskinen		case IS_ARRAY:
336b4892511SJani Taskinen			ZEND_PUTS("Array (");
337b4892511SJani Taskinen			if (++Z_ARRVAL_P(expr)->nApplyCount>1) {
338b4892511SJani Taskinen				ZEND_PUTS(" *RECURSION*");
339b4892511SJani Taskinen				Z_ARRVAL_P(expr)->nApplyCount--;
340b4892511SJani Taskinen				return;
341b4892511SJani Taskinen			}
342b4892511SJani Taskinen			print_flat_hash(Z_ARRVAL_P(expr) TSRMLS_CC);
343b4892511SJani Taskinen			ZEND_PUTS(")");
344b4892511SJani Taskinen			Z_ARRVAL_P(expr)->nApplyCount--;
345b4892511SJani Taskinen			break;
346b4892511SJani Taskinen		case IS_OBJECT:
347b4892511SJani Taskinen		{
3489bba373aSStanislav Malyshev			HashTable *properties = NULL;
3499bba373aSStanislav Malyshev			char *class_name = NULL;
3509bba373aSStanislav Malyshev			zend_uint clen;
3518ce1211aSMarcus Boerger
352f30f3590SStanislav Malyshev			if (Z_OBJ_HANDLER_P(expr, get_class_name)) {
3539bba373aSStanislav Malyshev				Z_OBJ_HANDLER_P(expr, get_class_name)(expr, &class_name, &clen, 0 TSRMLS_CC);
3549bba373aSStanislav Malyshev			}
355b4892511SJani Taskinen			if (class_name) {
356b4892511SJani Taskinen				zend_printf("%s Object (", class_name);
357b4892511SJani Taskinen			} else {
358b4892511SJani Taskinen				zend_printf("%s Object (", "Unknown Class");
359b4892511SJani Taskinen			}
360288daccaSAndi Gutmans			if (class_name) {
361ad01495aSStanislav Malyshev				efree(class_name);
3629bba373aSStanislav Malyshev			}
363f30f3590SStanislav Malyshev			if (Z_OBJ_HANDLER_P(expr, get_properties)) {
3649bba373aSStanislav Malyshev				properties = Z_OBJPROP_P(expr);
3659bba373aSStanislav Malyshev			}
366f30f3590SStanislav Malyshev			if (properties) {
3679bba373aSStanislav Malyshev				if (++properties->nApplyCount>1) {
3689bba373aSStanislav Malyshev					ZEND_PUTS(" *RECURSION*");
3699bba373aSStanislav Malyshev					properties->nApplyCount--;
3709bba373aSStanislav Malyshev					return;
3719bba373aSStanislav Malyshev				}
37224db7f18SSebastian Bergmann				print_flat_hash(properties TSRMLS_CC);
3739bba373aSStanislav Malyshev				properties->nApplyCount--;
3749bba373aSStanislav Malyshev			}
3759bba373aSStanislav Malyshev			ZEND_PUTS(")");
3769bba373aSStanislav Malyshev			break;
377b4892511SJani Taskinen		}
378b4892511SJani Taskinen		default:
379b4892511SJani Taskinen			zend_print_variable(expr);
380b4892511SJani Taskinen			break;
381b4892511SJani Taskinen	}
38227de54b0SAndi Gutmans}
383b4892511SJani Taskinen/* }}} */
384573b4602SAndi Gutmans
385b4892511SJani TaskinenZEND_API void zend_print_zval_r(zval *expr, int indent TSRMLS_DC) /* {{{ */
3865dba4774SZeev Suraski{
38724db7f18SSebastian Bergmann	zend_print_zval_r_ex(zend_write, expr, indent TSRMLS_CC);
3885dba4774SZeev Suraski}
389b4892511SJani Taskinen/* }}} */
3905dba4774SZeev Suraski
391b4892511SJani TaskinenZEND_API void zend_print_zval_r_ex(zend_write_func_t write_func, zval *expr, int indent TSRMLS_DC) /* {{{ */
392573b4602SAndi Gutmans{
393b4892511SJani Taskinen	switch (Z_TYPE_P(expr)) {
394573b4602SAndi Gutmans		case IS_ARRAY:
395d3d02fbcSDmitry Stogov			ZEND_PUTS_EX("Array\n");
396b4892511SJani Taskinen			if (++Z_ARRVAL_P(expr)->nApplyCount>1) {
397d3d02fbcSDmitry Stogov				ZEND_PUTS_EX(" *RECURSION*");
398b4892511SJani Taskinen				Z_ARRVAL_P(expr)->nApplyCount--;
3996053f2a1SZeev Suraski				return;
4006053f2a1SZeev Suraski			}
401d3d02fbcSDmitry Stogov			print_hash(write_func, Z_ARRVAL_P(expr), indent, 0 TSRMLS_CC);
402b4892511SJani Taskinen			Z_ARRVAL_P(expr)->nApplyCount--;
403573b4602SAndi Gutmans			break;
404573b4602SAndi Gutmans		case IS_OBJECT:
405c259cb7cSAndi Gutmans			{
4068ce1211aSMarcus Boerger				HashTable *properties;
4079bba373aSStanislav Malyshev				char *class_name = NULL;
4089bba373aSStanislav Malyshev				zend_uint clen;
4098ce1211aSMarcus Boerger				int is_temp;
4108ce1211aSMarcus Boerger
411f30f3590SStanislav Malyshev				if (Z_OBJ_HANDLER_P(expr, get_class_name)) {
4129bba373aSStanislav Malyshev					Z_OBJ_HANDLER_P(expr, get_class_name)(expr, &class_name, &clen, 0 TSRMLS_CC);
4139bba373aSStanislav Malyshev				}
414f1fb77d1SIlia Alshanetsky				if (class_name) {
415d3d02fbcSDmitry Stogov					ZEND_PUTS_EX(class_name);
416f1fb77d1SIlia Alshanetsky				} else {
417d3d02fbcSDmitry Stogov					ZEND_PUTS_EX("Unknown Class");
418f1fb77d1SIlia Alshanetsky				}
419d3d02fbcSDmitry Stogov				ZEND_PUTS_EX(" Object\n");
420288daccaSAndi Gutmans				if (class_name) {
421ad01495aSStanislav Malyshev					efree(class_name);
4229bba373aSStanislav Malyshev				}
4238ce1211aSMarcus Boerger				if ((properties = Z_OBJDEBUG_P(expr, is_temp)) == NULL) {
4248ce1211aSMarcus Boerger					break;
4259bba373aSStanislav Malyshev				}
4268ce1211aSMarcus Boerger				if (++properties->nApplyCount>1) {
427d3d02fbcSDmitry Stogov					ZEND_PUTS_EX(" *RECURSION*");
4289bba373aSStanislav Malyshev					properties->nApplyCount--;
4298ce1211aSMarcus Boerger					return;
4308ce1211aSMarcus Boerger				}
431d3d02fbcSDmitry Stogov				print_hash(write_func, properties, indent, 1 TSRMLS_CC);
4328ce1211aSMarcus Boerger				properties->nApplyCount--;
4338ce1211aSMarcus Boerger				if (is_temp) {
4348ce1211aSMarcus Boerger					zend_hash_destroy(properties);
4358ce1211aSMarcus Boerger					efree(properties);
436c259cb7cSAndi Gutmans				}
437c259cb7cSAndi Gutmans				break;
4386053f2a1SZeev Suraski			}
439573b4602SAndi Gutmans		default:
440d3d02fbcSDmitry Stogov			zend_print_zval_ex(write_func, expr, indent);
441573b4602SAndi Gutmans			break;
442573b4602SAndi Gutmans	}
443573b4602SAndi Gutmans}
444b4892511SJani Taskinen/* }}} */
445573b4602SAndi Gutmans
44685ab4235SFelipe Penastatic FILE *zend_fopen_wrapper(const char *filename, char **opened_path TSRMLS_DC) /* {{{ */
447573b4602SAndi Gutmans{
4485463dd5bSAndi Gutmans	if (opened_path) {
44927de5001SAndi Gutmans		*opened_path = estrdup(filename);
4505463dd5bSAndi Gutmans	}
451f311ab16SAndi Gutmans	return fopen(filename, "rb");
452573b4602SAndi Gutmans}
453b4892511SJani Taskinen/* }}} */
454573b4602SAndi Gutmans
4552f586e96SDmitry Stogov#ifdef ZTS
4568c885b89SDmitry Stogovstatic zend_bool asp_tags_default		  = 0;
4578c885b89SDmitry Stogovstatic zend_bool short_tags_default		  = 1;
4588c885b89SDmitry Stogovstatic zend_uint compiler_options_default = ZEND_COMPILE_DEFAULT;
4592f586e96SDmitry Stogov#else
4608c885b89SDmitry Stogov# define asp_tags_default			0
4618c885b89SDmitry Stogov# define short_tags_default			1
4628c885b89SDmitry Stogov# define compiler_options_default	ZEND_COMPILE_DEFAULT
4632f586e96SDmitry Stogov#endif
4642f586e96SDmitry Stogov
465b4892511SJani Taskinenstatic void zend_set_default_compile_time_values(TSRMLS_D) /* {{{ */
4668b794bb1SZeev Suraski{
4678b794bb1SZeev Suraski	/* default compile-time values */
4682f586e96SDmitry Stogov	CG(asp_tags) = asp_tags_default;
4692f586e96SDmitry Stogov	CG(short_tags) = short_tags_default;
4708c885b89SDmitry Stogov	CG(compiler_options) = compiler_options_default;
4718b794bb1SZeev Suraski}
472b4892511SJani Taskinen/* }}} */
4738b794bb1SZeev Suraski
474fcaa1c6dSDmitry Stogovstatic void zend_init_exception_op(TSRMLS_D) /* {{{ */
475fcaa1c6dSDmitry Stogov{
476fcaa1c6dSDmitry Stogov	memset(EG(exception_op), 0, sizeof(EG(exception_op)));
477fcaa1c6dSDmitry Stogov	EG(exception_op)[0].opcode = ZEND_HANDLE_EXCEPTION;
47894dd8372SDmitry Stogov	EG(exception_op)[0].op1_type = IS_UNUSED;
47994dd8372SDmitry Stogov	EG(exception_op)[0].op2_type = IS_UNUSED;
48094dd8372SDmitry Stogov	EG(exception_op)[0].result_type = IS_UNUSED;
481fcaa1c6dSDmitry Stogov	ZEND_VM_SET_OPCODE_HANDLER(EG(exception_op));
482fcaa1c6dSDmitry Stogov	EG(exception_op)[1].opcode = ZEND_HANDLE_EXCEPTION;
48394dd8372SDmitry Stogov	EG(exception_op)[1].op1_type = IS_UNUSED;
48494dd8372SDmitry Stogov	EG(exception_op)[1].op2_type = IS_UNUSED;
48594dd8372SDmitry Stogov	EG(exception_op)[1].result_type = IS_UNUSED;
486fcaa1c6dSDmitry Stogov	ZEND_VM_SET_OPCODE_HANDLER(EG(exception_op)+1);
487fcaa1c6dSDmitry Stogov	EG(exception_op)[2].opcode = ZEND_HANDLE_EXCEPTION;
48894dd8372SDmitry Stogov	EG(exception_op)[2].op1_type = IS_UNUSED;
48994dd8372SDmitry Stogov	EG(exception_op)[2].op2_type = IS_UNUSED;
49094dd8372SDmitry Stogov	EG(exception_op)[2].result_type = IS_UNUSED;
491fcaa1c6dSDmitry Stogov	ZEND_VM_SET_OPCODE_HANDLER(EG(exception_op)+2);
492fcaa1c6dSDmitry Stogov}
493fcaa1c6dSDmitry Stogov/* }}} */
494fcaa1c6dSDmitry Stogov
4957a87fcbbSZeev Suraski#ifdef ZTS
496b4892511SJani Taskinenstatic void compiler_globals_ctor(zend_compiler_globals *compiler_globals TSRMLS_DC) /* {{{ */
4977a87fcbbSZeev Suraski{
4987c4a0838SZeev Suraski	zend_function tmp_func;
499334ddd12SAndi Gutmans	zend_class_entry *tmp_class;
5007c4a0838SZeev Suraski
5017f4909d9SThies C. Arntzen	compiler_globals->compiled_filename = NULL;
5027f4909d9SThies C. Arntzen
503f7f5a5eaSStanislav Malyshev	compiler_globals->function_table = (HashTable *) malloc(sizeof(HashTable));
504b4892511SJani Taskinen	zend_hash_init_ex(compiler_globals->function_table, 100, NULL, ZEND_FUNCTION_DTOR, 1, 0);
505b4892511SJani Taskinen	zend_hash_copy(compiler_globals->function_table, global_function_table, NULL, &tmp_func, sizeof(zend_function));
5067a87fcbbSZeev Suraski
507b4892511SJani Taskinen	compiler_globals->class_table = (HashTable *) malloc(sizeof(HashTable));
508b4892511SJani Taskinen	zend_hash_init_ex(compiler_globals->class_table, 10, NULL, ZEND_CLASS_DTOR, 1, 0);
509b4892511SJani Taskinen	zend_hash_copy(compiler_globals->class_table, global_class_table, (copy_ctor_func_t) zend_class_add_ref, &tmp_class, sizeof(zend_class_entry *));
5109cf1a98dSThies C. Arntzen
511b4f3b9d3SZeev Suraski	zend_set_default_compile_time_values(TSRMLS_C);
51285b4df53SZeev Suraski
51385b4df53SZeev Suraski	CG(interactive) = 0;
5149d11db12SAndi Gutmans
5159d11db12SAndi Gutmans	compiler_globals->auto_globals = (HashTable *) malloc(sizeof(HashTable));
5169d11db12SAndi Gutmans	zend_hash_init_ex(compiler_globals->auto_globals, 8, NULL, NULL, 1, 0);
517f7b78004SZeev Suraski	zend_hash_copy(compiler_globals->auto_globals, global_auto_globals_table, NULL, NULL, sizeof(zend_auto_global) /* empty element */);
5188768ab94SDmitry Stogov
5198768ab94SDmitry Stogov	compiler_globals->last_static_member = zend_hash_num_elements(compiler_globals->class_table);
5208768ab94SDmitry Stogov	if (compiler_globals->last_static_member) {
521f23e8576SDmitry Stogov		compiler_globals->static_members_table = calloc(compiler_globals->last_static_member, sizeof(zval**));
5228768ab94SDmitry Stogov	} else {
523f23e8576SDmitry Stogov		compiler_globals->static_members_table = NULL;
5248768ab94SDmitry Stogov	}
5257a87fcbbSZeev Suraski}
526b4892511SJani Taskinen/* }}} */
5277a87fcbbSZeev Suraski
528b4892511SJani Taskinenstatic void compiler_globals_dtor(zend_compiler_globals *compiler_globals TSRMLS_DC) /* {{{ */
5297a87fcbbSZeev Suraski{
530ce98c73fSAndi Gutmans	if (compiler_globals->function_table != GLOBAL_FUNCTION_TABLE) {
53174a9ed7bSZeev Suraski		zend_hash_destroy(compiler_globals->function_table);
5328fb5ea30SMarcus Boerger		free(compiler_globals->function_table);
53374a9ed7bSZeev Suraski	}
534ce98c73fSAndi Gutmans	if (compiler_globals->class_table != GLOBAL_CLASS_TABLE) {
53574a9ed7bSZeev Suraski		zend_hash_destroy(compiler_globals->class_table);
5368fb5ea30SMarcus Boerger		free(compiler_globals->class_table);
53774a9ed7bSZeev Suraski	}
5388fb5ea30SMarcus Boerger	if (compiler_globals->auto_globals != GLOBAL_AUTO_GLOBALS_TABLE) {
5399d11db12SAndi Gutmans		zend_hash_destroy(compiler_globals->auto_globals);
5409d11db12SAndi Gutmans		free(compiler_globals->auto_globals);
5419d11db12SAndi Gutmans	}
542f23e8576SDmitry Stogov	if (compiler_globals->static_members_table) {
543f23e8576SDmitry Stogov		free(compiler_globals->static_members_table);
5448768ab94SDmitry Stogov	}
545bbf3d43cSMoriyoshi Koizumi	if (compiler_globals->script_encoding_list) {
546bbf3d43cSMoriyoshi Koizumi		pefree(compiler_globals->script_encoding_list, 1);
547bbf3d43cSMoriyoshi Koizumi	}
5488768ab94SDmitry Stogov	compiler_globals->last_static_member = 0;
5497a87fcbbSZeev Suraski}
550b4892511SJani Taskinen/* }}} */
551a9f9ae79SZeev Suraski
552b4892511SJani Taskinenstatic void executor_globals_ctor(zend_executor_globals *executor_globals TSRMLS_DC) /* {{{ */
553a9f9ae79SZeev Suraski{
5545fcae67eSZeev Suraski	zend_startup_constants(TSRMLS_C);
5555fcae67eSZeev Suraski	zend_copy_constants(EG(zend_constants), GLOBAL_CONSTANTS_TABLE);
5562c254ba7SZeev Suraski	zend_init_rsrc_plist(TSRMLS_C);
557fcaa1c6dSDmitry Stogov	zend_init_exception_op(TSRMLS_C);
558b4892511SJani Taskinen	EG(lambda_count) = 0;
5591f23e507SZeev Suraski	EG(user_error_handler) = NULL;
56004788f95SStig Bakken	EG(user_exception_handler) = NULL;
561ab30c8ccSZeev Suraski	EG(in_execution) = 0;
56255cf45abSDmitry Stogov	EG(in_autoload) = NULL;
563e6054d28SDerick Rethans	EG(current_execute_data) = NULL;
56452303217SMarcus Boerger	EG(current_module) = NULL;
5659d576212SAntony Dovgal	EG(exit_status) = 0;
566ee4f5ac1SFelipe Pena#if XPFPA_HAVE_CW
567ee4f5ac1SFelipe Pena	EG(saved_fpu_cw) = 0;
568ee4f5ac1SFelipe Pena#endif
56925710a40SFelipe Pena	EG(saved_fpu_cw_ptr) = NULL;
570d6ee9d48SAntony Dovgal	EG(active) = 0;
571a9f9ae79SZeev Suraski}
572b4892511SJani Taskinen/* }}} */
573a9f9ae79SZeev Suraski
574b4892511SJani Taskinenstatic void executor_globals_dtor(zend_executor_globals *executor_globals TSRMLS_DC) /* {{{ */
575a9f9ae79SZeev Suraski{
5762c254ba7SZeev Suraski	zend_ini_shutdown(TSRMLS_C);
57721698c12SDmitry Stogov	if (&executor_globals->persistent_list != global_persistent_list) {
57821698c12SDmitry Stogov		zend_destroy_rsrc_list(&executor_globals->persistent_list TSRMLS_CC);
57921698c12SDmitry Stogov	}
58021698c12SDmitry Stogov	if (executor_globals->zend_constants != GLOBAL_CONSTANTS_TABLE) {
58121698c12SDmitry Stogov		zend_hash_destroy(executor_globals->zend_constants);
58221698c12SDmitry Stogov		free(executor_globals->zend_constants);
58321698c12SDmitry Stogov	}
584a9f9ae79SZeev Suraski}
585b4892511SJani Taskinen/* }}} */
586a9f9ae79SZeev Suraski
587b4892511SJani Taskinenstatic void zend_new_thread_end_handler(THREAD_T thread_id TSRMLS_DC) /* {{{ */
588609d58a4SZeev Suraski{
589a84a2eaeSDmitry Stogov	if (zend_copy_ini_directives(TSRMLS_C) == SUCCESS) {
590a84a2eaeSDmitry Stogov		zend_ini_refresh_caches(ZEND_INI_STAGE_STARTUP TSRMLS_CC);
591a84a2eaeSDmitry Stogov	}
592609d58a4SZeev Suraski}
593b4892511SJani Taskinen/* }}} */
59466d9314bSZeev Suraski#endif
59566d9314bSZeev Suraski
596d46f8078SJon Parise#if defined(__FreeBSD__) || defined(__DragonFly__)
597d46f8078SJon Parise/* FreeBSD and DragonFly floating point precision fix */
5985928970dSAndi Gutmans#include <floatingpoint.h>
5995928970dSAndi Gutmans#endif
6007a87fcbbSZeev Suraski
601af316021SMarcus Boergerstatic void ini_scanner_globals_ctor(zend_ini_scanner_globals *scanner_globals_p TSRMLS_DC) /* {{{ */
602af316021SMarcus Boerger{
603af316021SMarcus Boerger	memset(scanner_globals_p, 0, sizeof(*scanner_globals_p));
604af316021SMarcus Boerger}
605af316021SMarcus Boerger/* }}} */
606af316021SMarcus Boerger
607af316021SMarcus Boergerstatic void php_scanner_globals_ctor(zend_php_scanner_globals *scanner_globals_p TSRMLS_DC) /* {{{ */
60854d53055SZeev Suraski{
609af316021SMarcus Boerger	memset(scanner_globals_p, 0, sizeof(*scanner_globals_p));
61054d53055SZeev Suraski}
611b4892511SJani Taskinen/* }}} */
61254d53055SZeev Suraski
613226c56feSJani Taskinenvoid zend_init_opcodes_handlers(void);
61454d53055SZeev Suraski
615f0c8366aSDmitry Stogovstatic zend_bool php_auto_globals_create_globals(char *name, uint name_len TSRMLS_DC) /* {{{ */
616f0c8366aSDmitry Stogov{
617f0c8366aSDmitry Stogov	zval *globals;
618f0c8366aSDmitry Stogov
619f0c8366aSDmitry Stogov	ALLOC_ZVAL(globals);
620f0c8366aSDmitry Stogov	Z_SET_REFCOUNT_P(globals, 1);
621f0c8366aSDmitry Stogov	Z_SET_ISREF_P(globals);
622f0c8366aSDmitry Stogov	Z_TYPE_P(globals) = IS_ARRAY;
623f0c8366aSDmitry Stogov	Z_ARRVAL_P(globals) = &EG(symbol_table);
624f0c8366aSDmitry Stogov	zend_hash_update(&EG(symbol_table), name, name_len + 1, &globals, sizeof(zval *), NULL);
625f0c8366aSDmitry Stogov	return 0;
626f0c8366aSDmitry Stogov}
627f0c8366aSDmitry Stogov/* }}} */
628f0c8366aSDmitry Stogov
6292faea53dSMarcus Boergerint zend_startup(zend_utility_functions *utility_functions, char **extensions TSRMLS_DC) /* {{{ */
630573b4602SAndi Gutmans{
631a9f9ae79SZeev Suraski#ifdef ZTS
6327c4a0838SZeev Suraski	zend_compiler_globals *compiler_globals;
633a9f9ae79SZeev Suraski	zend_executor_globals *executor_globals;
634609d58a4SZeev Suraski	extern ZEND_API ts_rsrc_id ini_scanner_globals_id;
635609d58a4SZeev Suraski	extern ZEND_API ts_rsrc_id language_scanner_globals_id;
636609d58a4SZeev Suraski#else
637af316021SMarcus Boerger	extern zend_ini_scanner_globals ini_scanner_globals;
638af316021SMarcus Boerger	extern zend_php_scanner_globals language_scanner_globals;
639609d58a4SZeev Suraski#endif
640a9f9ae79SZeev Suraski
64129ed52ffSDmitry Stogov	start_memory_manager(TSRMLS_C);
642a9f9ae79SZeev Suraski
643d46f8078SJon Parise#if defined(__FreeBSD__) || defined(__DragonFly__)
644d46f8078SJon Parise	/* FreeBSD and DragonFly floating point precision fix */
645c3340584SSascha Schumann	fpsetmask(0);
6465928970dSAndi Gutmans#endif
647309827ecSZeev Suraski
6484d44a5b7SAntony Dovgal	zend_startup_strtod();
649309827ecSZeev Suraski	zend_startup_extensions_mechanism();
650309827ecSZeev Suraski
651573b4602SAndi Gutmans	/* Set up utility functions and values */
65267f69743SZeev Suraski	zend_error_cb = utility_functions->error_function;
653573b4602SAndi Gutmans	zend_printf = utility_functions->printf_function;
6545dba4774SZeev Suraski	zend_write = (zend_write_func_t) utility_functions->write_function;
655573b4602SAndi Gutmans	zend_fopen = utility_functions->fopen_function;
656573b4602SAndi Gutmans	if (!zend_fopen) {
657573b4602SAndi Gutmans		zend_fopen = zend_fopen_wrapper;
658573b4602SAndi Gutmans	}
659e52aac94SWez Furlong	zend_stream_open_function = utility_functions->stream_open_function;
66056251a72SZeev Suraski	zend_message_dispatcher_p = utility_functions->message_handler;
661573b4602SAndi Gutmans	zend_block_interruptions = utility_functions->block_interruptions;
662573b4602SAndi Gutmans	zend_unblock_interruptions = utility_functions->unblock_interruptions;
663903018efSZeev Suraski	zend_get_configuration_directive_p = utility_functions->get_configuration_directive;
664fafbf6d8SZeev Suraski	zend_ticks_function = utility_functions->ticks_function;
665bd115087SZeev Suraski	zend_on_timeout = utility_functions->on_timeout;
666d45fd8a1SMarcus Boerger	zend_vspprintf = utility_functions->vspprintf_function;
66785a36e2bSZeev Suraski	zend_getenv = utility_functions->getenv_function;
668ab232458SDmitry Stogov	zend_resolve_path = utility_functions->resolve_path_function;
669d035af4aSZeev Suraski
67008b9fdc8SDavid Soria Parra#if HAVE_DTRACE
67108b9fdc8SDavid Soria Parra/* build with dtrace support */
67208b9fdc8SDavid Soria Parra	zend_compile_file = dtrace_compile_file;
67308b9fdc8SDavid Soria Parra	zend_execute = dtrace_execute;
67408b9fdc8SDavid Soria Parra	zend_execute_internal = dtrace_execute_internal;
67508b9fdc8SDavid Soria Parra#else
676c06692e9SZeev Suraski	zend_compile_file = compile_file;
677573b4602SAndi Gutmans	zend_execute = execute;
6782c44fab3SDerick Rethans	zend_execute_internal = NULL;
67908b9fdc8SDavid Soria Parra#endif /* HAVE_SYS_SDT_H */
68008b9fdc8SDavid Soria Parra	zend_compile_string = compile_string;
681979da661SAndi Gutmans	zend_throw_exception_hook = NULL;
682573b4602SAndi Gutmans
683cf36abb2SAndi Gutmans	zend_init_opcodes_handlers();
684cf36abb2SAndi Gutmans
685573b4602SAndi Gutmans	/* set up version */
686573b4602SAndi Gutmans	zend_version_info = strdup(ZEND_CORE_VERSION_INFO);
687b4892511SJani Taskinen	zend_version_info_length = sizeof(ZEND_CORE_VERSION_INFO) - 1;
688b4892511SJani Taskinen
689b4892511SJani Taskinen	GLOBAL_FUNCTION_TABLE = (HashTable *) malloc(sizeof(HashTable));
690b4892511SJani Taskinen	GLOBAL_CLASS_TABLE = (HashTable *) malloc(sizeof(HashTable));
691b4892511SJani Taskinen	GLOBAL_AUTO_GLOBALS_TABLE = (HashTable *) malloc(sizeof(HashTable));
692b4892511SJani Taskinen	GLOBAL_CONSTANTS_TABLE = (HashTable *) malloc(sizeof(HashTable));
693573b4602SAndi Gutmans
6941263932aSZeev Suraski	zend_hash_init_ex(GLOBAL_FUNCTION_TABLE, 100, NULL, ZEND_FUNCTION_DTOR, 1, 0);
6951263932aSZeev Suraski	zend_hash_init_ex(GLOBAL_CLASS_TABLE, 10, NULL, ZEND_CLASS_DTOR, 1, 0);
696f0c8366aSDmitry Stogov	zend_hash_init_ex(GLOBAL_AUTO_GLOBALS_TABLE, 8, NULL, NULL, 1, 0);
697b4892511SJani Taskinen	zend_hash_init_ex(GLOBAL_CONSTANTS_TABLE, 20, NULL, ZEND_CONSTANT_DTOR, 1, 0);
6982eabb14dSAndi Gutmans
6991263932aSZeev Suraski	zend_hash_init_ex(&module_registry, 50, NULL, ZEND_MODULE_DTOR, 1, 0);
7004cb9a483SZeev Suraski	zend_init_rsrc_list_dtors();
701573b4602SAndi Gutmans
702213d0e2fSAndi Gutmans	/* This zval can be used to initialize allocate zval's to an uninit'ed value */
7034b4d634cSYiduo (David) Wang	Z_UNSET_ISREF(zval_used_for_init);
7044b4d634cSYiduo (David) Wang	Z_SET_REFCOUNT(zval_used_for_init, 1);
705b4892511SJani Taskinen	Z_TYPE(zval_used_for_init) = IS_NULL;
706213d0e2fSAndi Gutmans
7077a87fcbbSZeev Suraski#ifdef ZTS
7082c254ba7SZeev Suraski	ts_allocate_id(&compiler_globals_id, sizeof(zend_compiler_globals), (ts_allocate_ctor) compiler_globals_ctor, (ts_allocate_dtor) compiler_globals_dtor);
7092c254ba7SZeev Suraski	ts_allocate_id(&executor_globals_id, sizeof(zend_executor_globals), (ts_allocate_ctor) executor_globals_ctor, (ts_allocate_dtor) executor_globals_dtor);
710af316021SMarcus Boerger	ts_allocate_id(&language_scanner_globals_id, sizeof(zend_php_scanner_globals), (ts_allocate_ctor) php_scanner_globals_ctor, NULL);
711af316021SMarcus Boerger	ts_allocate_id(&ini_scanner_globals_id, sizeof(zend_ini_scanner_globals), (ts_allocate_ctor) ini_scanner_globals_ctor, NULL);
7127c4a0838SZeev Suraski	compiler_globals = ts_resource(compiler_globals_id);
713a9f9ae79SZeev Suraski	executor_globals = ts_resource(executor_globals_id);
7145fcae67eSZeev Suraski
7158fb5ea30SMarcus Boerger	compiler_globals_dtor(compiler_globals TSRMLS_CC);
7162a8426a6SMarcus Boerger	compiler_globals->in_compilation = 0;
7178fb5ea30SMarcus Boerger	compiler_globals->function_table = (HashTable *) malloc(sizeof(HashTable));
7188fb5ea30SMarcus Boerger	compiler_globals->class_table = (HashTable *) malloc(sizeof(HashTable));
7198fb5ea30SMarcus Boerger
720f4b832d2SAndi Gutmans	*compiler_globals->function_table = *GLOBAL_FUNCTION_TABLE;
721f4b832d2SAndi Gutmans	*compiler_globals->class_table = *GLOBAL_CLASS_TABLE;
7229d11db12SAndi Gutmans	compiler_globals->auto_globals = GLOBAL_AUTO_GLOBALS_TABLE;
7235fcae67eSZeev Suraski
7245fcae67eSZeev Suraski	zend_hash_destroy(executor_globals->zend_constants);
7255fcae67eSZeev Suraski	*executor_globals->zend_constants = *GLOBAL_CONSTANTS_TABLE;
726762158aaSAndi Gutmans#else
727af316021SMarcus Boerger	ini_scanner_globals_ctor(&ini_scanner_globals TSRMLS_CC);
728af316021SMarcus Boerger	php_scanner_globals_ctor(&language_scanner_globals TSRMLS_CC);
729b4f3b9d3SZeev Suraski	zend_set_default_compile_time_values(TSRMLS_C);
7301f23e507SZeev Suraski	EG(user_error_handler) = NULL;
73104788f95SStig Bakken	EG(user_exception_handler) = NULL;
7327a87fcbbSZeev Suraski#endif
733826cc0dcSMarcus Boerger
734dd5c478bSDmitry Stogov	zend_interned_strings_init(TSRMLS_C);
7352faea53dSMarcus Boerger	zend_startup_builtin_functions(TSRMLS_C);
7362c254ba7SZeev Suraski	zend_register_standard_constants(TSRMLS_C);
737f0c8366aSDmitry Stogov	zend_register_auto_global("GLOBALS", sizeof("GLOBALS") - 1, 1, php_auto_globals_create_globals TSRMLS_CC);
7387a87fcbbSZeev Suraski
739bfbe8618SZeev Suraski#ifndef ZTS
7402c254ba7SZeev Suraski	zend_init_rsrc_plist(TSRMLS_C);
741fcaa1c6dSDmitry Stogov	zend_init_exception_op(TSRMLS_C);
742bfbe8618SZeev Suraski#endif
743a9f9ae79SZeev Suraski
7442c254ba7SZeev Suraski	zend_ini_startup(TSRMLS_C);
74554d53055SZeev Suraski
74654d53055SZeev Suraski#ifdef ZTS
74754d53055SZeev Suraski	tsrm_set_new_thread_end_handler(zend_new_thread_end_handler);
74854d53055SZeev Suraski#endif
74954d53055SZeev Suraski
750573b4602SAndi Gutmans	return SUCCESS;
751573b4602SAndi Gutmans}
752b4892511SJani Taskinen/* }}} */
753573b4602SAndi Gutmans
754b4892511SJani Taskinenvoid zend_register_standard_ini_entries(TSRMLS_D) /* {{{ */
7554be862b0SZeev Suraski{
7564be862b0SZeev Suraski	int module_number = 0;
7574be862b0SZeev Suraski
7584be862b0SZeev Suraski	REGISTER_INI_ENTRIES();
7594be862b0SZeev Suraski}
760b4892511SJani Taskinen/* }}} */
7614be862b0SZeev Suraski
762711be83dSZeev Suraski/* Unlink the global (r/o) copies of the class, function and constant tables,
763711be83dSZeev Suraski * and use a fresh r/w copy for the startup thread
764711be83dSZeev Suraski */
765b4892511SJani Taskinenvoid zend_post_startup(TSRMLS_D) /* {{{ */
766711be83dSZeev Suraski{
767b4892511SJani Taskinen#ifdef ZTS
768711be83dSZeev Suraski	zend_compiler_globals *compiler_globals = ts_resource(compiler_globals_id);
7695fcae67eSZeev Suraski	zend_executor_globals *executor_globals = ts_resource(executor_globals_id);
770711be83dSZeev Suraski
7715fcae67eSZeev Suraski	*GLOBAL_FUNCTION_TABLE = *compiler_globals->function_table;
7725fcae67eSZeev Suraski	*GLOBAL_CLASS_TABLE = *compiler_globals->class_table;
7735fcae67eSZeev Suraski	*GLOBAL_CONSTANTS_TABLE = *executor_globals->zend_constants;
7742f586e96SDmitry Stogov
7752f586e96SDmitry Stogov	asp_tags_default = CG(asp_tags);
7762f586e96SDmitry Stogov	short_tags_default = CG(short_tags);
7778c885b89SDmitry Stogov	compiler_options_default = CG(compiler_options);
7788ce1211aSMarcus Boerger
779b817dab2SZeev Suraski	zend_destroy_rsrc_list(&EG(persistent_list) TSRMLS_CC);
7808fb5ea30SMarcus Boerger	free(compiler_globals->function_table);
7818fb5ea30SMarcus Boerger	free(compiler_globals->class_table);
782711be83dSZeev Suraski	compiler_globals_ctor(compiler_globals, tsrm_ls);
7838fb5ea30SMarcus Boerger	free(EG(zend_constants));
7845fcae67eSZeev Suraski	executor_globals_ctor(executor_globals, tsrm_ls);
78521698c12SDmitry Stogov	global_persistent_list = &EG(persistent_list);
786a84a2eaeSDmitry Stogov	zend_copy_ini_directives(TSRMLS_C);
787711be83dSZeev Suraski#endif
788b4892511SJani Taskinen}
789b4892511SJani Taskinen/* }}} */
790711be83dSZeev Suraski
791b4892511SJani Taskinenvoid zend_shutdown(TSRMLS_D) /* {{{ */
792573b4602SAndi Gutmans{
79384eb48f0SZeev Suraski#ifdef ZEND_WIN32
79484eb48f0SZeev Suraski	zend_shutdown_timeout_thread();
79584eb48f0SZeev Suraski#endif
7969e1beb4fSDmitry Stogov	zend_destroy_rsrc_list(&EG(persistent_list) TSRMLS_CC);
7971a1178a6SDmitry Stogov	zend_destroy_modules();
7983458373eSAndi Gutmans
7997a87fcbbSZeev Suraski	zend_hash_destroy(GLOBAL_FUNCTION_TABLE);
80076b9acc1SAndi Gutmans	zend_hash_destroy(GLOBAL_CLASS_TABLE);
8013458373eSAndi Gutmans
8029d11db12SAndi Gutmans	zend_hash_destroy(GLOBAL_AUTO_GLOBALS_TABLE);
8039d11db12SAndi Gutmans	free(GLOBAL_AUTO_GLOBALS_TABLE);
8042da8b014Sfoobar
805d76cf1daSZeev Suraski	zend_shutdown_extensions(TSRMLS_C);
806573b4602SAndi Gutmans	free(zend_version_info);
80748b33032SSterling Hughes
808a2513618SMarcus Boerger	free(GLOBAL_FUNCTION_TABLE);
809a2513618SMarcus Boerger	free(GLOBAL_CLASS_TABLE);
81021698c12SDmitry Stogov
81148b33032SSterling Hughes	zend_hash_destroy(GLOBAL_CONSTANTS_TABLE);
812a54c7dcbSMarcus Boerger	free(GLOBAL_CONSTANTS_TABLE);
8134d44a5b7SAntony Dovgal	zend_shutdown_strtod();
814b4892511SJani Taskinen
81521698c12SDmitry Stogov#ifdef ZTS
8168fb5ea30SMarcus Boerger	GLOBAL_FUNCTION_TABLE = NULL;
8178fb5ea30SMarcus Boerger	GLOBAL_CLASS_TABLE = NULL;
8188fb5ea30SMarcus Boerger	GLOBAL_AUTO_GLOBALS_TABLE = NULL;
81921698c12SDmitry Stogov	GLOBAL_CONSTANTS_TABLE = NULL;
820a17d2f37SSebastian Bergmann#endif
8214c283fffSIlia Alshanetsky	zend_destroy_rsrc_list_dtors();
822dd5c478bSDmitry Stogov
823dd5c478bSDmitry Stogov	zend_interned_strings_dtor(TSRMLS_C);
824573b4602SAndi Gutmans}
825b4892511SJani Taskinen/* }}} */
826573b4602SAndi Gutmans
827b4892511SJani Taskinenvoid zend_set_utility_values(zend_utility_values *utility_values) /* {{{ */
8287656c77cSZeev Suraski{
8297656c77cSZeev Suraski	zend_uv = *utility_values;
8309baad804SZeev Suraski	zend_uv.import_use_extension_length = strlen(zend_uv.import_use_extension);
8317656c77cSZeev Suraski}
832b4892511SJani Taskinen/* }}} */
8337656c77cSZeev Suraski
834573b4602SAndi Gutmans/* this should be compatible with the standard zenderror */
835cf7384aaSFelipe Penavoid zenderror(const char *error) /* {{{ */
836573b4602SAndi Gutmans{
83710def9a8SIlia Alshanetsky	zend_error(E_PARSE, "%s", error);
838573b4602SAndi Gutmans}
839b4892511SJani Taskinen/* }}} */
840573b4602SAndi Gutmans
841b0bfa458SZeev SuraskiBEGIN_EXTERN_C()
842b4892511SJani TaskinenZEND_API void _zend_bailout(char *filename, uint lineno) /* {{{ */
843573b4602SAndi Gutmans{
8442c254ba7SZeev Suraski	TSRMLS_FETCH();
845573b4602SAndi Gutmans
84614f6b914SDmitry Stogov	if (!EG(bailout)) {
847ef4fe54fSZeev Suraski		zend_output_debug_string(1, "%s(%d) : Bailed out without a bailout address!", filename, lineno);
848931ebe08SZeev Suraski		exit(-1);
849931ebe08SZeev Suraski	}
8506bc6dacfSZeev Suraski	CG(unclean_shutdown) = 1;
851b23d83cfSZeev Suraski	CG(in_compilation) = EG(in_execution) = 0;
852bdc35c9fSThies C. Arntzen	EG(current_execute_data) = NULL;
85310afe5d9SRasmus Lerdorf	LONGJMP(*EG(bailout), FAILURE);
854573b4602SAndi Gutmans}
855b4892511SJani Taskinen/* }}} */
856b0bfa458SZeev SuraskiEND_EXTERN_C()
857573b4602SAndi Gutmans
858cf7384aaSFelipe Penavoid zend_append_version_info(const zend_extension *extension) /* {{{ */
859573b4602SAndi Gutmans{
860573b4602SAndi Gutmans	char *new_info;
861573b4602SAndi Gutmans	uint new_info_length;
862573b4602SAndi Gutmans
863573b4602SAndi Gutmans	new_info_length = sizeof("    with  v,  by \n")
864573b4602SAndi Gutmans						+ strlen(extension->name)
865573b4602SAndi Gutmans						+ strlen(extension->version)
866573b4602SAndi Gutmans						+ strlen(extension->copyright)
867573b4602SAndi Gutmans						+ strlen(extension->author);
868573b4602SAndi Gutmans
869b4892511SJani Taskinen	new_info = (char *) malloc(new_info_length + 1);
870573b4602SAndi Gutmans
871573b4602SAndi Gutmans	sprintf(new_info, "    with %s v%s, %s, by %s\n", extension->name, extension->version, extension->copyright, extension->author);
872573b4602SAndi Gutmans
873b4892511SJani Taskinen	zend_version_info = (char *) realloc(zend_version_info, zend_version_info_length+new_info_length + 1);
874573b4602SAndi Gutmans	strcat(zend_version_info, new_info);
875573b4602SAndi Gutmans	zend_version_info_length += new_info_length;
876573b4602SAndi Gutmans	free(new_info);
877573b4602SAndi Gutmans}
878b4892511SJani Taskinen/* }}} */
879573b4602SAndi Gutmans
880b4892511SJani TaskinenZEND_API char *get_zend_version(void) /* {{{ */
881573b4602SAndi Gutmans{
882573b4602SAndi Gutmans	return zend_version_info;
883573b4602SAndi Gutmans}
884b4892511SJani Taskinen/* }}} */
885ed06a70fSZeev Suraski
886b4892511SJani Taskinenvoid zend_activate(TSRMLS_D) /* {{{ */
887ed06a70fSZeev Suraski{
88871592cecSDmitry Stogov	gc_reset(TSRMLS_C);
889b4f3b9d3SZeev Suraski	init_compiler(TSRMLS_C);
890b4f3b9d3SZeev Suraski	init_executor(TSRMLS_C);
891b4f3b9d3SZeev Suraski	startup_scanner(TSRMLS_C);
892ed06a70fSZeev Suraski}
893b4892511SJani Taskinen/* }}} */
894ed06a70fSZeev Suraski
895b4892511SJani Taskinenvoid zend_call_destructors(TSRMLS_D) /* {{{ */
8960cd2da03SMarcus Boerger{
8970cd2da03SMarcus Boerger	zend_try {
8980cd2da03SMarcus Boerger		shutdown_destructors(TSRMLS_C);
8990cd2da03SMarcus Boerger	} zend_end_try();
9000cd2da03SMarcus Boerger}
901b4892511SJani Taskinen/* }}} */
9020cd2da03SMarcus Boerger
903b4892511SJani Taskinenvoid zend_deactivate(TSRMLS_D) /* {{{ */
904ed06a70fSZeev Suraski{
905372f71ebSThies C. Arntzen	/* we're no longer executing anything */
906424e98f4SZeev Suraski	EG(opline_ptr) = NULL;
907372f71ebSThies C. Arntzen	EG(active_symbol_table) = NULL;
908f4c9d96fSThies C. Arntzen
909931ebe08SZeev Suraski	zend_try {
910b4f3b9d3SZeev Suraski		shutdown_scanner(TSRMLS_C);
911931ebe08SZeev Suraski	} zend_end_try();
912931ebe08SZeev Suraski
9138084d278SZeev Suraski	/* shutdown_executor() takes care of its own bailout handling */
9142c254ba7SZeev Suraski	shutdown_executor(TSRMLS_C);
915931ebe08SZeev Suraski
916931ebe08SZeev Suraski	zend_try {
917b4f3b9d3SZeev Suraski		shutdown_compiler(TSRMLS_C);
918931ebe08SZeev Suraski	} zend_end_try();
919931ebe08SZeev Suraski
92059a46c34SDmitry Stogov	zend_destroy_rsrc_list(&EG(regular_list) TSRMLS_CC);
92159a46c34SDmitry Stogov
92271592cecSDmitry Stogov#ifdef ZEND_DEBUG
92371592cecSDmitry Stogov	if (GC_G(gc_enabled) && !CG(unclean_shutdown)) {
92471592cecSDmitry Stogov		gc_collect_cycles(TSRMLS_C);
92571592cecSDmitry Stogov	}
92671592cecSDmitry Stogov#endif
92771592cecSDmitry Stogov
9283bd291e1SDerick Rethans#if GC_BENCH
92913d75ce6SDerick Rethans	fprintf(stderr, "GC Statistics\n");
93013d75ce6SDerick Rethans	fprintf(stderr, "-------------\n");
93113d75ce6SDerick Rethans	fprintf(stderr, "Runs:               %d\n", GC_G(gc_runs));
93213d75ce6SDerick Rethans	fprintf(stderr, "Collected:          %d\n", GC_G(collected));
93313d75ce6SDerick Rethans	fprintf(stderr, "Root buffer length: %d\n", GC_G(root_buf_length));
93413d75ce6SDerick Rethans	fprintf(stderr, "Root buffer peak:   %d\n\n", GC_G(root_buf_peak));
93513d75ce6SDerick Rethans	fprintf(stderr, "      Possible            Remove from  Marked\n");
93613d75ce6SDerick Rethans	fprintf(stderr, "        Root    Buffered     buffer     grey\n");
93713d75ce6SDerick Rethans	fprintf(stderr, "      --------  --------  -----------  ------\n");
93813d75ce6SDerick Rethans	fprintf(stderr, "ZVAL  %8d  %8d  %9d  %8d\n", GC_G(zval_possible_root), GC_G(zval_buffered), GC_G(zval_remove_from_buffer), GC_G(zval_marked_grey));
93913d75ce6SDerick Rethans	fprintf(stderr, "ZOBJ  %8d  %8d  %9d  %8d\n", GC_G(zobj_possible_root), GC_G(zobj_buffered), GC_G(zobj_remove_from_buffer), GC_G(zobj_marked_grey));
9403bd291e1SDerick Rethans#endif
9413bd291e1SDerick Rethans
942931ebe08SZeev Suraski	zend_try {
9432c254ba7SZeev Suraski		zend_ini_deactivate(TSRMLS_C);
944931ebe08SZeev Suraski	} zend_end_try();
945ed06a70fSZeev Suraski}
946b4892511SJani Taskinen/* }}} */
94756251a72SZeev Suraski
948fc173b6aSSam RubyBEGIN_EXTERN_C()
94985ab4235SFelipe PenaZEND_API void zend_message_dispatcher(long message, void *data TSRMLS_DC) /* {{{ */
95056251a72SZeev Suraski{
95156251a72SZeev Suraski	if (zend_message_dispatcher_p) {
95285ab4235SFelipe Pena		zend_message_dispatcher_p(message, data TSRMLS_CC);
95356251a72SZeev Suraski	}
95456251a72SZeev Suraski}
955b4892511SJani Taskinen/* }}} */
956fc173b6aSSam RubyEND_EXTERN_C()
95756251a72SZeev Suraski
958cf7384aaSFelipe PenaZEND_API int zend_get_configuration_directive(const char *name, uint name_length, zval *contents) /* {{{ */
95956251a72SZeev Suraski{
960903018efSZeev Suraski	if (zend_get_configuration_directive_p) {
961903018efSZeev Suraski		return zend_get_configuration_directive_p(name, name_length, contents);
96256251a72SZeev Suraski	} else {
96356251a72SZeev Suraski		return FAILURE;
96456251a72SZeev Suraski	}
96556251a72SZeev Suraski}
966b4892511SJani Taskinen/* }}} */
96767f69743SZeev Suraski
968b4892511SJani TaskinenZEND_API void zend_error(int type, const char *format, ...) /* {{{ */
96967f69743SZeev Suraski{
97067f69743SZeev Suraski	va_list args;
9719e9c193eSStanislav Malyshev	va_list usr_copy;
9723cda6a75SZeev Suraski	zval ***params;
9733cda6a75SZeev Suraski	zval *retval;
974f34b9d41SZeev Suraski	zval *z_error_type, *z_error_message, *z_error_filename, *z_error_lineno, *z_context;
975b80b8381SZeev Suraski	char *error_filename;
976b80b8381SZeev Suraski	uint error_lineno;
977a31dc47aSZeev Suraski	zval *orig_user_error_handler;
9782e1a2438SDmitry Stogov	zend_bool in_compilation;
9792e1a2438SDmitry Stogov	zend_class_entry *saved_class_entry;
9802c254ba7SZeev Suraski	TSRMLS_FETCH();
98167f69743SZeev Suraski
982b80b8381SZeev Suraski	/* Obtain relevant filename and lineno */
983b80b8381SZeev Suraski	switch (type) {
984b80b8381SZeev Suraski		case E_CORE_ERROR:
985b80b8381SZeev Suraski		case E_CORE_WARNING:
986b80b8381SZeev Suraski			error_filename = NULL;
987b80b8381SZeev Suraski			error_lineno = 0;
988b80b8381SZeev Suraski			break;
989b80b8381SZeev Suraski		case E_PARSE:
990b80b8381SZeev Suraski		case E_COMPILE_ERROR:
991b80b8381SZeev Suraski		case E_COMPILE_WARNING:
992b80b8381SZeev Suraski		case E_ERROR:
993b80b8381SZeev Suraski		case E_NOTICE:
994c0df4502SAndi Gutmans		case E_STRICT:
995d3e50265SMarcus Boerger		case E_DEPRECATED:
996b80b8381SZeev Suraski		case E_WARNING:
997b80b8381SZeev Suraski		case E_USER_ERROR:
998b80b8381SZeev Suraski		case E_USER_WARNING:
999b80b8381SZeev Suraski		case E_USER_NOTICE:
1000d619b57eSHannes Magnusson		case E_USER_DEPRECATED:
10018a03fc5eSAntony Dovgal		case E_RECOVERABLE_ERROR:
10024187439cSZeev Suraski			if (zend_is_compiling(TSRMLS_C)) {
1003b4f3b9d3SZeev Suraski				error_filename = zend_get_compiled_filename(TSRMLS_C);
1004b4f3b9d3SZeev Suraski				error_lineno = zend_get_compiled_lineno(TSRMLS_C);
10054187439cSZeev Suraski			} else if (zend_is_executing(TSRMLS_C)) {
10062c254ba7SZeev Suraski				error_filename = zend_get_executed_filename(TSRMLS_C);
10072c254ba7SZeev Suraski				error_lineno = zend_get_executed_lineno(TSRMLS_C);
1008b80b8381SZeev Suraski			} else {
1009b80b8381SZeev Suraski				error_filename = NULL;
1010