#21486 [Dup->Bgs]: $this pointer not always pointing to the right object

From: Date: Wed, 08 Jan 2003 01:29:43 +0000
Subject: #21486 [Dup->Bgs]: $this pointer not always pointing to the right object
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-29387@lists.php.net to get a copy of this message
ID: 21486 Updated by: sniper@php.net Reported By: corinl@gmx.de -Status: Duplicate +Status: Bogus Bug Type: Class/Object related Operating System: windows PHP Version: 4.3.0 Previous Comments: ------------------------------------------------------------------------ [2003-01-07 07:39:38] alan_k@php.net $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. ------------------------------------------------------------------------ [2003-01-07 06:19:33] corinl@gmx.de hi, 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 -> "); print_r($this); echo("<br>"); } } class cb { function debug() { echo("cb::debug -> "); print_r($this); echo("<br>"); } function test() { cb::debug(); ca::debug(); } } $b = new cb; $b->test(); ----- 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!! ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=21486&edit=1

« previous php.bugs (#29387) next »