Req #69027 [Opn]: Backtrace does not include class
| From: | krakjoe@php.net | Date: | Tue, 12 Apr 2016 17:50:42 +0000 |
| Subject: | Req #69027 [Opn]: Backtrace does not include class | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-200510@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=69027&edit=1
ID: 69027
Updated by: krakjoe@php.net
Reported by: roborg at gmail dot com
Summary: Backtrace does not include class
Status: Open
Type: Feature/Change Request
Package: Unknown/Other Function
Operating System: N/A
PHP Version: 7.0.0beta1
Block user comment: N
Private report: N
New Comment:
I agree, it might be useful in some cases.
However, for the information to be provided by default in traces, we would need to change the
default behaviour of the function.
This has non-obvious implications, possibly effecting things like unit testing, or some other
components that rely on the format of a trace.
Here is a patch: http://pastebin.com/fKwxbBaZ
I haven't changed the default behaviour in the patch, only made it possible to get called
class.
What I would suggest is that you play with the patch, and when you are happy with it, whip up an
RFC: http://wiki.php.net/rfc/howto
I'm going to suspend the report, because nobody can act on this request without an RFC.
Previous Comments:
------------------------------------------------------------------------
[2015-07-21 07:46:22] roborg at gmail dot com
This affects all PHP versions, but PHP7 seems the ideal time to add it
------------------------------------------------------------------------
[2015-02-11 10:20:12] roborg at gmail dot com
Description:
------------
The backtrace (either from an exception or debug_backtrace) doesn't contain an entry for the
class of the object that a method was called on - only the class that the method was defined in.
In the example below, there's even though the call is on a B object, there's no mention of
B in the backtrace, which cane make debugging very difficult.
I would suggest adding an extra item to the trace, e.g. "object_class", alongside class.
Test script:
---------------
<?php
class A
{
protected $val = 0;
public function ex()
{
throw new Exception('Value is ' . $this->val);
}
}
class B extends A
{
protected $val = 1;
}
try
{
$b = new B();
$b->ex();
}
catch (Exception $e)
{
print '<pre>' . print_r($e->getTrace(), true) . '</pre>';
}
Expected result:
----------------
Array
(
[0] => Array
(
[file] => C:\bug.php
[line] => 21
[function] => ex
[class] => A
[object_class] => B
[type] => ->
[args] => Array
(
)
)
)
Actual result:
--------------
Array
(
[0] => Array
(
[file] => C:\bug.php
[line] => 21
[function] => ex
[class] => A
[type] => ->
[args] => Array
(
)
)
)
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=69027&edit=1