From: Sebastian Bergmann Date: Tue, 1 Nov 2005 13:18:34 +0000 (+0000) Subject: Add an additional field $frame['object'] to the result array of debug_backtrace(... X-Git-Tag: RELEASE_2_0_1~84 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=5d671dd4b26c3c13b78807a50abf5fe4482888ae;p=php Add an additional field $frame['object'] to the result array of debug_backtrace() that contains a reference to the respective object when the frame was called from an object. This revised patch has been reviewed by Dmitry and Zeev. --- diff --git a/Zend/zend_builtin_functions.c b/Zend/zend_builtin_functions.c index 5967cfc5f2..de9358625b 100644 --- a/Zend/zend_builtin_functions.c +++ b/Zend/zend_builtin_functions.c @@ -1906,7 +1906,7 @@ ZEND_FUNCTION(debug_print_backtrace) /* }}} */ -ZEND_API void zend_fetch_debug_backtrace(zval *return_value, int skip_last TSRMLS_DC) +ZEND_API void zend_fetch_debug_backtrace(zval *return_value, int skip_last, int provide_object TSRMLS_DC) { zend_execute_data *ptr, *skip; int lineno; @@ -2005,6 +2005,11 @@ ZEND_API void zend_fetch_debug_backtrace(zval *return_value, int skip_last TSRML dup = zend_get_object_classname(ptr->object, &class_name, &class_name_len TSRMLS_CC); add_assoc_text_ex(stack_frame, "class", sizeof("class"), class_name, dup); } + if (provide_object) { + add_assoc_zval_ex(stack_frame, "object", sizeof("object"), ptr->object); + ptr->object->refcount++; + } + add_assoc_ascii_string_ex(stack_frame, "type", sizeof("type"), "->", 1); } else if (ptr->function_state.function->common.scope) { add_assoc_textl_ex(stack_frame, "class", sizeof("class"), ptr->function_state.function->common.scope->name, ptr->function_state.function->common.scope->name_length, 1); @@ -2086,7 +2091,7 @@ ZEND_FUNCTION(debug_backtrace) ZEND_WRONG_PARAM_COUNT(); } - zend_fetch_debug_backtrace(return_value, 1 TSRMLS_CC); + zend_fetch_debug_backtrace(return_value, 1, 1 TSRMLS_CC); } /* }}} */ diff --git a/Zend/zend_builtin_functions.h b/Zend/zend_builtin_functions.h index e5304360c1..d8f06c61f6 100644 --- a/Zend/zend_builtin_functions.h +++ b/Zend/zend_builtin_functions.h @@ -25,7 +25,7 @@ int zend_startup_builtin_functions(TSRMLS_D); BEGIN_EXTERN_C() -ZEND_API void zend_fetch_debug_backtrace(zval *return_value, int skip_last TSRMLS_DC); +ZEND_API void zend_fetch_debug_backtrace(zval *return_value, int skip_last, int provide_object TSRMLS_DC); END_EXTERN_C() #endif /* ZEND_BUILTIN_FUNCTIONS_H */ diff --git a/Zend/zend_exceptions.c b/Zend/zend_exceptions.c index 2659687db9..1c7a32761e 100644 --- a/Zend/zend_exceptions.c +++ b/Zend/zend_exceptions.c @@ -92,7 +92,7 @@ static zend_object_value zend_default_exception_new_ex(zend_class_entry *class_t ALLOC_ZVAL(trace); trace->is_ref = 0; trace->refcount = 0; - zend_fetch_debug_backtrace(trace, skip_top_traces TSRMLS_CC); + zend_fetch_debug_backtrace(trace, skip_top_traces, 0 TSRMLS_CC); zend_update_property_rt_string(U_CLASS_ENTRY(default_exception_ce), &obj, "file", sizeof("file")-1, zend_get_executed_filename(TSRMLS_C) TSRMLS_CC); zend_update_property_long(U_CLASS_ENTRY(default_exception_ce), &obj, "line", sizeof("line")-1, zend_get_executed_lineno(TSRMLS_C) TSRMLS_CC);