ID:               34986
 Updated by:       [EMAIL PROTECTED]
 Reported By:      [EMAIL PROTECTED]
-Status:           Open
+Status:           Closed
 Bug Type:         Feature/Change Request
 Operating System: Irrelevant
 PHP Version:      5.1.0RC3
 New Comment:

This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.




Previous Comments:
------------------------------------------------------------------------

[2005-10-26 11:03:09] [EMAIL PROTECTED]

Revised patch, takes care of reference counting (thanks to Derick for
pointing this out):

Index: zend_builtin_functions.c
===================================================================
RCS file: /repository/ZendEngine2/zend_builtin_functions.c,v
retrieving revision 1.277.2.5
diff -u -b -B -r1.277.2.5 zend_builtin_functions.c
--- zend_builtin_functions.c    16 Sep 2005 17:05:06 -0000      1.277.2.5
+++ zend_builtin_functions.c    26 Oct 2005 08:56:29 -0000
@@ -1913,6 +1913,9 @@
                                        add_assoc_string_ex(stack_frame, 
"class", sizeof("class"),
class_name, dup);
                                        
                                }
+                               add_assoc_zval_ex(stack_frame, "object", 
sizeof("object"),
ptr->object);
+                               ptr->object->refcount++;
+
                                add_assoc_string_ex(stack_frame, "type", 
sizeof("type"), "->",
1);
                        } else if (ptr->function_state.function->common.scope) {
                                add_assoc_string_ex(stack_frame, "class", 
sizeof("class"),
ptr->function_state.function->common.scope->name, 1);

------------------------------------------------------------------------

[2005-10-26 10:45:53] [EMAIL PROTECTED]

The patch below seems to work. If it really does, this was too easy
:-)

Index: zend_builtin_functions.c
===================================================================
RCS file: /repository/ZendEngine2/zend_builtin_functions.c,v
retrieving revision 1.277.2.5
diff -u -b -B -r1.277.2.5 zend_builtin_functions.c
--- zend_builtin_functions.c    16 Sep 2005 17:05:06 -0000      1.277.2.5
+++ zend_builtin_functions.c    26 Oct 2005 08:44:25 -0000
@@ -1914,6 +1914,7 @@
                                        
                                }
                                add_assoc_string_ex(stack_frame, "type", 
sizeof("type"), "->",
1);
+                               add_assoc_zval_ex(stack_frame, "object", 
sizeof("object"),
ptr->object);
                        } else if (ptr->function_state.function->common.scope) {
                                add_assoc_string_ex(stack_frame, "class", 
sizeof("class"),
ptr->function_state.function->common.scope->name, 1);
                                add_assoc_string_ex(stack_frame, "type", 
sizeof("type"), "::", 1);

------------------------------------------------------------------------

[2005-10-26 09:40:49] [EMAIL PROTECTED]

Just a clarification: [object] should contain a reference to the
object, not an "Object id #x" string. That is only in the example
output as that is what would happen for print_r(debug_backtrace()).

------------------------------------------------------------------------

[2005-10-26 06:53:59] [EMAIL PROTECTED]

Description:
------------
For some Meta Programming it would be great if debug_backtrace() could
return an [object] field (in addition to [class] that contains a
reference to respective object.

Reproduce code:
---------------
<?php
class A {
  private $b;

  public function __construct()  {
    $this->b = new B;
  }

  public function aMethod() {
    $this->b->bMethod();
  }
}

class B {
  public function bMethod() {
    print_r(debug_backtrace());
  }
}

$a = new A;
$a->aMethod();
?>

Expected result:
----------------
Array
(
    [0] => Array
        (
            [file] => /home/sb/test.php
            [line] => 10
            [function] => bMethod
            [class] => B
            [object] => <Object id #2>
            [type] => ->
            [args] => Array
                (
                )

        )

    [1] => Array
        (
            [file] => /home/sb/test.php
            [line] => 21
            [function] => aMethod
            [class] => A
            [object] => <Object id #1>
            [type] => ->
            [args] => Array
                (
                )

        )

)

Actual result:
--------------
Array
(
    [0] => Array
        (
            [file] => /home/sb/test.php
            [line] => 10
            [function] => bMethod
            [class] => B
            [type] => ->
            [args] => Array
                (
                )

        )

    [1] => Array
        (
            [file] => /home/sb/test.php
            [line] => 21
            [function] => aMethod
            [class] => A
            [type] => ->
            [args] => Array
                (
                )

        )

)


------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=34986&edit=1

Reply via email to