]> granicus.if.org Git - php/commitdiff
Fixed bug #30828 (debug_backtrace() reports incorrect class in overridden methods)
authorDmitry Stogov <dmitry@php.net>
Thu, 23 Jun 2005 09:23:03 +0000 (09:23 +0000)
committerDmitry Stogov <dmitry@php.net>
Thu, 23 Jun 2005 09:23:03 +0000 (09:23 +0000)
NEWS
Zend/tests/bug30828.phpt [new file with mode: 0755]
Zend/zend_builtin_functions.c

diff --git a/NEWS b/NEWS
index d5c69d170640441d5984326964e528222fa4590f..bb0c5de69173e364e454e9dd6611578659da158a 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -137,6 +137,8 @@ PHP                                                                        NEWS
   (Dmitry)
 - Fixed bug #30889 (Conflict between __get/__set and ++ operator). (Dmitry)
 - Fixed bug #30833 (array_count_values() modifying input array). (Tony)
+- Fixed bug #30828 (debug_backtrace() reports incorrect class in overridden
+  methods). (Dmitry)
 - Fixed bug #30820 (static member conflict with $this->member silently
   ignored). (Dmitry)
 - Fixed bug #30819 (Better support for LDAP SASL bind). (Jani)
diff --git a/Zend/tests/bug30828.phpt b/Zend/tests/bug30828.phpt
new file mode 100755 (executable)
index 0000000..d05dbb6
--- /dev/null
@@ -0,0 +1,61 @@
+--TEST--
+Bug #30828 (debug_backtrace() reports incorrect class in overridden methods)
+--FILE--
+<?php
+class A {
+       function __construct() {
+               debug_print_backtrace();
+               $bt = debug_backtrace();
+               foreach ($bt as $t) {
+                       print $t['class'].$t['type'].$t['function']."\n";
+               }
+       }
+
+       function foo() {
+               debug_print_backtrace();
+               $bt = debug_backtrace();
+               foreach ($bt as $t) {
+                        print $t['class'].$t['type'].$t['function']."\n";
+               }
+       }
+
+       static function bar() {
+               debug_print_backtrace();
+               $bt = debug_backtrace();
+               foreach ($bt as $t) {
+                       print $t['class'].$t['type'].$t['function']."\n";
+               }
+       }
+}
+
+class B extends A {
+       function __construct() {
+               parent::__construct();
+       }
+
+       function foo() {
+               parent::foo();
+       }
+
+       static function bar() {
+               parent::bar();
+       }
+}
+
+$b = new B();
+$b->foo();
+B::bar();
+?>
+--EXPECTF--
+#0  A->__construct() called at [%sbug30828.php:30]
+#1  B->__construct() called at [%sbug30828.php:42]
+A->__construct
+B->__construct
+#0  A->foo() called at [%sbug30828.php:34]
+#1  B->foo() called at [%sbug30828.php:43]
+A->foo
+B->foo
+#0  A::bar() called at [%sbug30828.php:38]
+#1  B::bar() called at [%sbug30828.php:44]
+A::bar
+B::bar
index d5324da41ac0886b197b7f895bde4392b58d1119..346fef10c410a128bccf6bf1cf881314ec9e3bb4 100644 (file)
@@ -1620,13 +1620,16 @@ ZEND_FUNCTION(debug_print_backtrace)
 
                if (function_name) {
                        if (ptr->object) {
-                               zend_uint class_name_len;
-                               if (Z_OBJ_HT_P(ptr->object)->get_class_name == NULL ||
-                               Z_OBJ_HT_P(ptr->object)->get_class_name(ptr->object, &class_name, &class_name_len, 0 TSRMLS_CC) != SUCCESS) {
-
-                                       class_name = Z_OBJCE(*ptr->object)->name;
+                               if (ptr->function_state.function->common.scope) {
+                                       class_name = ptr->function_state.function->common.scope->name;
                                } else {
-                                       free_class_name = class_name;
+                                       zend_uint class_name_len;
+                                       if (Z_OBJ_HT_P(ptr->object)->get_class_name == NULL ||
+                                           Z_OBJ_HT_P(ptr->object)->get_class_name(ptr->object, &class_name, &class_name_len, 0 TSRMLS_CC) != SUCCESS) {
+                                               class_name = Z_OBJCE(*ptr->object)->name;
+                                       } else {
+                                               free_class_name = class_name;
+                                       }
                                }
                                call_type = "->";
                        } else if (ptr->function_state.function->common.scope) {
@@ -1778,12 +1781,16 @@ ZEND_API void zend_fetch_debug_backtrace(zval *return_value, int skip_last TSRML
                        add_assoc_string_ex(stack_frame, "function", sizeof("function"), function_name, 1);
 
                        if (ptr->object && Z_TYPE_P(ptr->object) == IS_OBJECT) {
-                               zend_uint class_name_len;
-                               if (Z_OBJ_HT_P(ptr->object)->get_class_name == NULL ||
-                    Z_OBJ_HT_P(ptr->object)->get_class_name(ptr->object, &class_name, &class_name_len, 0 TSRMLS_CC) != SUCCESS) {
-                                       add_assoc_string_ex(stack_frame, "class", sizeof("class"), Z_OBJCE(*ptr->object)->name, 1);
+                               if (ptr->function_state.function->common.scope) {
+                                       add_assoc_string_ex(stack_frame, "class", sizeof("class"), ptr->function_state.function->common.scope->name, 1);
                                } else {
-                                       add_assoc_string_ex(stack_frame, "class", sizeof("class"), class_name, 0);
+                                       zend_uint class_name_len;
+                                       if (Z_OBJ_HT_P(ptr->object)->get_class_name == NULL ||
+                                           Z_OBJ_HT_P(ptr->object)->get_class_name(ptr->object, &class_name, &class_name_len, 0 TSRMLS_CC) != SUCCESS) {
+                                               add_assoc_string_ex(stack_frame, "class", sizeof("class"), Z_OBJCE(*ptr->object)->name, 1);
+                                       } else {
+                                               add_assoc_string_ex(stack_frame, "class", sizeof("class"), class_name, 0);
+                                       }
                                }
                                add_assoc_string_ex(stack_frame, "type", sizeof("type"), "->", 1);
                        } else if (ptr->function_state.function->common.scope) {