|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2008-07-25 02:45 UTC] kelvin at netbasic dot co dot uk
Description:
------------
When calling a static function from inside of a class the backtrace / stacktrace reports the call as a normal object call, i.e. its showing ->, where it really should show ::
Reproduce code:
---------------
<?php
class testA
{
public function funcA()
{
testB::funcB();
}
}
class testB
{
public function funcB()
{
echo "<pre>";
debug_print_backtrace();
echo "</pre>";
}
}
$obj = new testA();
$obj->funcA();
?>
Expected result:
----------------
#0 testB::funcB() called at [/home/site3/public_html/t1.php:7]
#1 testA->funcA() called at [/home/site3/public_html/t1.php:23]
Actual result:
--------------
#0 testB->funcB() called at [/home/site3/public_html/t1.php:7]
#1 testA->funcA() called at [/home/site3/public_html/t1.php:23]
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Dec 10 19:00:01 2025 UTC |
This is not just a stacktrace problem. If you were to attempt use '$this' in funcB you would find that '$this' is actually available and is an instance of class testA. I stumbled on this accidentally. <?php class testA { public function funcA() { testB::funcB(); } } class testB { public function funcB() { echo get_class($this); } } $obj = new testA(); $obj->funcA(); ?> Expected result: ---------------- nothing Actual result: -------------- testA It appears as though the static method is being executed in the context of the calling object. Strange behaviour.