php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #47334 debug_backtrace() gives incorrect 'type' value
Submitted: 2009-02-07 14:32 UTC Modified: 2009-02-09 11:28 UTC
From: php at kennel17 dot co dot uk Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5.2.9RC1 OS: Win32
Private report: No CVE-ID: None
 [2009-02-07 14:32 UTC] php at kennel17 dot co dot uk
Description:
------------
The 'type' attribute returned by debug_backtrace() seems to always be set to "->" in PHP5, but was correctly set to "::" for static calls in PHP4.  I have tested this on 5.2.8, 5.2.9RC1 and 5.3.0beta1 and it applies to all of these.

In the example code, StaticFunc() is called statically from OtherFunc(), so the type field should contain "::", which it does in PHP4, but in PHP5 it contains "->", as you can see in the results below.

Note that this also affects debug_print_backtrace(), which gives the following output:

#0  MyClass->StaticFunc() called at [example.php:11]
#1  MyClass->OtherFunc() called at [example.php:16]

instead of what you would expect:

#0  MyClass::StaticFunc() called at [example.php:11]
#1  MyClass->OtherFunc() called at [example.php:16]


Reproduce code:
---------------
<?php

class MyClass {
	
	function StaticFunc() {
		print_r(debug_backtrace());
	}
	
	function OtherFunc() {
		MyClass::StaticFunc();
	}
}

$c = new MyClass;
$c->OtherFunc();

?>

Expected result:
----------------
PHP4 produces this, which is the expected result.  Note the 'type' field in element [0].

Array
(
    [0] => Array
        (
            [file] => example.php
            [line] => 11
            [function] => staticfunc
            [class] => myclass
            [type] => ::
            [args] => Array
                (
                )

        )

    [1] => Array
        (
            [file] => example.php
            [line] => 16
            [function] => otherfunc
            [class] => myclass
            [type] => ->
            [args] => Array
                (
                )

        )

)


Actual result:
--------------
PHP5 gives the following:

Array
(
    [0] => Array
        (
            [file] => example.php
            [line] => 11
            [function] => StaticFunc
            [class] => MyClass
            [object] => MyClass Object
                (
                )

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

        )

    [1] => Array
        (
            [file] => example.php
            [line] => 16
            [function] => OtherFunc
            [class] => MyClass
            [object] => MyClass Object
                (
                )

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

        )
)

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-02-08 16:02 UTC] iliaa@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

StaticFunc is not defined as static call, hence ->.
 [2009-02-09 11:28 UTC] php at kennel17 dot co dot uk
Not true.

If I call MyClass::StaticFunc() from outside a class method, then it correctly set the 'type' to "::", despite not being defined as static.  In the following example, I would expect the [0] index to be the same for all three calls:

Code:
-----

<?php

class MyClass {
	
	function StaticFunc() {
		print_r(debug_backtrace());
	}
	
	function OtherFunc() {
		MyClass::StaticFunc();
	}
}

$c = new MyClass;

MyClass::StaticFunc();
MyClass::OtherFunc();
$c->OtherFunc();

?>

Results:
--------
array index [0] (others omitted).  Aside from the line number, these should be identical.

Array
(
    [0] => Array
        (
            [file] => example.php
            [line] => 16
            [function] => StaticFunc
            [class] => MyClass
            [type] => ::
            [args] => Array
                (
                )

        )
        ...
)

Array
(
    [0] => Array
        (
            [file] => example.php
            [line] => 11
            [function] => StaticFunc
            [class] => MyClass
            [type] => ::
            [args] => Array
                (
                )

        )
        ...
)

Array
(
    [0] => Array
        (
            [file] => example.php
            [line] => 11
            [function] => StaticFunc
            [class] => MyClass
            [object] => MyClass Object
                (
                )

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

        )
        ...
)
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Mon Jul 07 23:01:32 2025 UTC