php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #45620 Stacktrace reports wrong call type for static methods called from non-static
Submitted: 2008-07-25 02:45 UTC Modified: 2010-03-07 22:19 UTC
Votes:2
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:0 (0.0%)
From: kelvin at netbasic dot co dot uk Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5.2.6 OS: CentOS 5
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: kelvin at netbasic dot co dot uk
New email:
PHP Version: OS:

 

 [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]



Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-08-05 02:08 UTC] coen at bluedogtraining dot com dot au
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.
 [2009-01-22 01:12 UTC] jani@php.net
Please try using this CVS snapshot:

  http://snaps.php.net/php5.2-latest.tar.gz
 
For Windows:

  http://windows.php.net/snapshots/


 [2009-01-30 01:00 UTC] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
 [2010-03-07 22:19 UTC] felipe@php.net
-Status: No Feedback +Status: Bogus
 [2010-03-07 22:19 UTC] felipe@php.net
This behavior is expected, because the method is called by passing $this when it isn't explicity declared static.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sun Jul 20 06:00:02 2025 UTC