|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #21486 $this pointer not always pointing to the right object
Submitted: 2003-01-07 06:19 UTC Modified: 2003-01-07 19:29 UTC
From: corinl at gmx dot de Assigned:
Status: Not a bug Package: Class/Object related
PHP Version: 4.3.0 OS: windows
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: corinl at gmx dot de
New email:
PHP Version: OS:


 [2003-01-07 06:19 UTC] corinl at gmx dot de
i found that the $this pointer does not always point to the current class, as it is supposted to.

run the following example code:
class ca
	function debug()
		echo("ca::debug -> ");

class cb
	function debug()
		echo("cb::debug -> ");
	function test()

$b = new cb;

output is:
cb::debug -> cb Object ( ) 
ca::debug -> cb Object ( ) 

but should'nt it be:
cb::debug -> cb Object ( ) 
ca::debug -> ca Object ( ) 

it seems that when a class is called like class::methode from within another class, the this pointer points to the calling class, not the current running class!!


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2003-01-07 07:39 UTC]
$this is that of the calling class when you use static method calls, The official line is dont rely on this behaviour as
it may change...
ref: php-dev mailing list.
 [2004-02-18 16:25 UTC] phpbugs at ynx dot de
Hey, I think this is something that really needs to be fixed!

The original testcase shows that $this evaluates to the instance of cb even in ca::debug, which is definitly NOT the behaviour one might expect!

I think $this should always evaluate to nothing when accessed inside a function that is called statically!
PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Tue Sep 26 20:01:27 2023 UTC