|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[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
(
)
)
)
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Dec 24 13:00:01 2025 UTC |
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 ( ) ) ... )