#45620 [Com]: Stacktrace reports wrong call type for static methods called from non-static

From: Date: Tue, 05 Aug 2008 02:08:36 +0000
Subject: #45620 [Com]: Stacktrace reports wrong call type for static methods called from non-static
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-127598@lists.php.net to get a copy of this message
 ID:               45620
 Comment by:       coen at bluedogtraining dot com dot au
 Reported By:      kelvin at netbasic dot co dot uk
 Status:           Open
 Bug Type:         Scripting Engine problem
 Operating System: CentOS 5
 PHP Version:      5.2.6
 New Comment:

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.


Previous Comments:
------------------------------------------------------------------------

[2008-07-25 02:45:45] 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]




------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=45620&edit=1



Thread (4 messages)

« previous php.bugs (#127598) next »