php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #65871 debug_backtrace missing 'file' & 'line' indices for reflection-invoked methods
Submitted: 2013-10-09 15:13 UTC Modified: 2013-11-08 07:25 UTC
Votes:1
Avg. Score:4.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:1 (100.0%)
From: jbeall at heraldic dot us Assigned:
Status: Open Package: Reflection related
PHP Version: 5.4.20 OS: Windows 8 & Ubuntu Linux
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: jbeall at heraldic dot us
New email:
PHP Version: OS:

 

 [2013-10-09 15:13 UTC] jbeall at heraldic dot us
Description:
------------
When using the debug_backtrace function, the resulting array will be missing 'file' and 'line' indices for any stack frames that were invoked via reflection.

The documentation for debug_backtrace does not indicate that stack frames for methods invoked via reflection will be missing any information.  If this is not a bug, the documentation should have a clear warning that this behavior is intentional.

Test script:
---------------
class SampleClass {

    public function printBacktrace() {
        print_r(debug_backtrace());
    }
}

$obj1 = new SampleClass();

echo "Invoked directly: ";
$obj1->printBacktrace();

$rm = new ReflectionMethod($obj1,'printBacktrace');

echo "\n\nInvoked via reflection: ";
$rm->invoke($obj1);

Expected result:
----------------
The stack frame for SampleClass->printBacktrace should include file and line number information regardless of whether the method was invoked via reflection.

Actual result:
--------------
Stack frames for methods invoked via reflection are missing file and line number information. Here's the output of the sample script:


Invoked directly: Array
(
    [0] => Array
        (
            [file] => /home/lamplighter/.apps/http/__default__/0/llpdn/1.0-zdc/public/test.php
            [line] => 15
            [function] => printBacktrace
            [class] => SampleClass
            [object] => SampleClass Object
                (
                )

            [type] => ->
            [args] => Array
                (
                )

        )

)


Invoked via reflection: Array
(
    [0] => Array
        (
            [function] => printBacktrace
            [class] => SampleClass
            [object] => SampleClass Object
                (
                )

            [type] => ->
            [args] => Array
                (
                )

        )

    [1] => Array
        (
            [file] => /home/lamplighter/.apps/http/__default__/0/llpdn/1.0-zdc/public/test.php
            [line] => 20
            [function] => invoke
            [class] => ReflectionMethod
            [object] => ReflectionMethod Object
                (
                    [name] => printBacktrace
                    [class] => SampleClass
                )

            [type] => ->
            [args] => Array
                (
                    [0] => SampleClass Object
                        (
                        )

                )

        )

)

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-11-03 11:52 UTC] felipe@php.net
-Package: Reflection related +Package: Documentation problem
 [2013-11-08 07:25 UTC] krakjoe@php.net
-Package: Documentation problem +Package: Reflection related
 [2013-11-08 07:25 UTC] krakjoe@php.net
This is expected behaviour, however, I'm not sure it's impossible to avoid. So before I go changing the documentation, can someone that works on reflection let me know if this can be fixed or if it should be documented ?
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Oct 07 17:01:28 2024 UTC