/* true multithread-shared globals */
ZEND_API zend_class_entry *zend_standard_class_def = NULL;
+ZEND_API zend_class_entry *zend_exception_class_def = NULL;
ZEND_API int (*zend_printf)(const char *format, ...);
ZEND_API zend_write_func_t zend_write;
ZEND_API FILE *(*zend_fopen)(const char *filename, char **opened_path);
}
+static void register_exception_class(void)
+{
+ zend_exception_class_def = malloc(sizeof(zend_class_entry));
+
+ zend_exception_class_def->type = ZEND_INTERNAL_CLASS;
+ zend_exception_class_def->name_length = sizeof("Exception") - 1;
+ zend_exception_class_def->name = zend_strndup("Exception", zend_exception_class_def->name_length);
+ zend_exception_class_def->parent = NULL;
+ zend_hash_init_ex(&zend_exception_class_def->default_properties, 0, NULL, ZVAL_PTR_DTOR, 1, 0);
+ zend_hash_init_ex(&zend_exception_class_def->private_properties, 0, NULL, ZVAL_PTR_DTOR, 1, 0);
+ zend_hash_init_ex(&zend_exception_class_def->protected_properties, 0, NULL, ZVAL_PTR_DTOR, 1, 0);
+ zend_exception_class_def->static_members = (HashTable *) malloc(sizeof(HashTable));
+ zend_hash_init_ex(zend_exception_class_def->static_members, 0, NULL, ZVAL_PTR_DTOR, 1, 0);
+ zend_hash_init_ex(&zend_exception_class_def->constants_table, 0, NULL, ZVAL_PTR_DTOR, 1, 0);
+ zend_hash_init_ex(&zend_exception_class_def->class_table, 10, NULL, ZEND_CLASS_DTOR, 1, 0);
+ zend_hash_init_ex(&zend_exception_class_def->function_table, 0, NULL, ZEND_FUNCTION_DTOR, 1, 0);
+ zend_exception_class_def->constructor = NULL;
+ zend_exception_class_def->destructor = NULL;
+ zend_exception_class_def->clone = NULL;
+ zend_exception_class_def->handle_function_call = NULL;
+ zend_exception_class_def->handle_property_get = NULL;
+ zend_exception_class_def->handle_property_set = NULL;
+ zend_exception_class_def->refcount = 1;
+ zend_hash_add(GLOBAL_CLASS_TABLE, "exception", sizeof("exception"), &zend_exception_class_def, sizeof(zend_class_entry *), NULL);
+}
+
+
static void zend_set_default_compile_time_values(TSRMLS_D)
{
/* default compile-time values */
zend_init_rsrc_plist(TSRMLS_C);
EG(lambda_count)=0;
EG(user_error_handler) = NULL;
+ EG(user_exception_handler) = NULL;
EG(in_execution) = 0;
}
zend_hash_init_ex(GLOBAL_AUTO_GLOBALS_TABLE, 8, NULL, NULL, 1, 0);
register_standard_class();
+ register_exception_class();
zend_hash_init_ex(&module_registry, 50, NULL, ZEND_MODULE_DTOR, 1, 0);
zend_init_rsrc_list_dtors();
+
/* This zval can be used to initialize allocate zval's to an uninit'ed value */
zval_used_for_init.is_ref = 0;
zval_used_for_init.refcount = 1;
zend_startup_constants();
zend_set_default_compile_time_values(TSRMLS_C);
EG(user_error_handler) = NULL;
+ EG(user_exception_handler) = NULL;
#endif
zend_register_standard_constants(TSRMLS_C);
EG(return_value_ptr_ptr) = retval ? retval : &local_retval;
zend_execute(EG(active_op_array) TSRMLS_CC);
if (EG(exception)) {
+#if 1 /* support set_exception_handler() */
+ if (EG(user_exception_handler)) {
+ zval *orig_user_exception_handler;
+ zval ***params, *retval2;
+ params = (zval ***)emalloc(sizeof(zval **));
+ params[0] = &EG(exception);
+ orig_user_exception_handler = EG(user_exception_handler);
+ if (call_user_function_ex(CG(function_table), NULL, orig_user_exception_handler, &retval2, 1, params, 1, NULL TSRMLS_CC) == SUCCESS) {
+ zval_ptr_dtor(&retval2);
+ }
+ efree(params);
+ zval_ptr_dtor(&EG(exception));
+ EG(exception) = NULL;
+ } else {
+ zval_ptr_dtor(&EG(exception));
+ EG(exception) = NULL;
+ zend_error(E_ERROR, "Uncaught exception!");
+ }
+ if (!retval) {
+ zval_ptr_dtor(EG(return_value_ptr_ptr));
+ local_retval = NULL;
+ }
+#else
zval_ptr_dtor(&EG(exception));
zend_error(E_ERROR, "Uncaught exception!");
+#endif
} else if (!retval) {
zval_ptr_dtor(EG(return_value_ptr_ptr));
local_retval = NULL;
static ZEND_FUNCTION(trigger_error);
static ZEND_FUNCTION(set_error_handler);
static ZEND_FUNCTION(restore_error_handler);
+static ZEND_FUNCTION(set_exception_handler);
+static ZEND_FUNCTION(restore_exception_handler);
static ZEND_FUNCTION(get_declared_classes);
static ZEND_FUNCTION(get_defined_functions);
static ZEND_FUNCTION(get_defined_vars);
ZEND_FALIAS(user_error, trigger_error, NULL)
ZEND_FE(set_error_handler, NULL)
ZEND_FE(restore_error_handler, NULL)
+ ZEND_FE(set_exception_handler, NULL)
+ ZEND_FE(restore_exception_handler, NULL)
ZEND_FE(get_declared_classes, NULL)
ZEND_FE(get_defined_functions, NULL)
ZEND_FE(get_defined_vars, NULL)
/* }}} */
+/* {{{ proto string set_exception_handler(string exception_handler)
+ Sets a user-defined exception handler function. Returns the previously defined exception handler, or false on error */
+ZEND_FUNCTION(set_exception_handler)
+{
+ zval **exception_handler;
+ zend_bool had_orig_exception_handler=0;
+
+ if (ZEND_NUM_ARGS()!=1 || zend_get_parameters_ex(1, &exception_handler)==FAILURE) {
+ ZEND_WRONG_PARAM_COUNT();
+ }
+
+ convert_to_string_ex(exception_handler);
+ if (EG(user_exception_handler)) {
+ had_orig_exception_handler = 1;
+ *return_value = *EG(user_exception_handler);
+ zval_copy_ctor(return_value);
+ zend_ptr_stack_push(&EG(user_exception_handlers), EG(user_exception_handler));
+ }
+ ALLOC_ZVAL(EG(user_exception_handler));
+
+ if (Z_STRLEN_PP(exception_handler)==0) { /* unset user-defined handler */
+ FREE_ZVAL(EG(user_exception_handler));
+ EG(user_exception_handler) = NULL;
+ RETURN_TRUE;
+ }
+
+ *EG(user_exception_handler) = **exception_handler;
+ zval_copy_ctor(EG(user_exception_handler));
+
+ if (!had_orig_exception_handler) {
+ RETURN_NULL();
+ }
+}
+/* }}} */
+
+
+/* {{{ proto void restore_exception_handler(void)
+ Restores the previously defined exception handler function */
+ZEND_FUNCTION(restore_exception_handler)
+{
+ if (EG(user_exception_handler)) {
+ zval_ptr_dtor(&EG(user_exception_handler));
+ }
+ if (zend_ptr_stack_num_elements(&EG(user_exception_handlers))==0) {
+ EG(user_exception_handler) = NULL;
+ } else {
+ EG(user_exception_handler) = zend_ptr_stack_pop(&EG(user_exception_handlers));
+ }
+ RETURN_TRUE;
+}
+/* }}} */
+
+
static int copy_class_name(zend_class_entry **pce, int num_args, va_list args, zend_hash_key *hash_key)
{
zval *array = va_arg(args, zval *);
char *function_name;
char *filename;
char *class_name;
- zend_uint class_name_length;
zval *stack_frame;
ptr = EG(current_execute_data);
if (ptr->object) {
class_name = Z_OBJCE(*ptr->object)->name;
- class_name_length = Z_OBJCE(*ptr->object)->name_length;
}
if (ptr->function_state.function->common.scope) {
class_name = ptr->function_state.function->common.scope->name;
}
}
/* }}} */
+
+/*
+ * Local variables:
+ * tab-width: 4
+ * c-basic-offset: 4
+ * indent-tabs-mode: t
+ * End:
+ */