PHP 4.0 Bug #9005 Updated: Static classes sometimes have a $this pointer

From: Date: Thu, 08 Mar 2001 10:51:37 +0000
Subject: PHP 4.0 Bug #9005 Updated: Static classes sometimes have a $this pointer
Groups: php.dev 
Request: Send a blank email to php-dev+get-48227@lists.php.net to get a copy of this message
ID: 9005 Updated by: zeev Reported By: chuck@horde.org Old-Status: Open Status: Closed Bug Type: Scripting Engine problem Assigned To: Comments: class::method() isn't a static call in PHP (it isn't always a static call in C++ either). The primary use for class::method() is actually calling methods from your parent class, not calling 'static methods' (the ability to create static classes and call their methods is pretty much a positive 'side effect'). So, this is the intended behavior. Previous Comments: --------------------------------------------------------------------------- [2001-01-30 13:39:15] chuck@horde.org If you call a static method from within an object, the static method will inherit the $this pointer of the calling object. This script demonstrates the problem: <?php error_reporting(E_ALL); class StaticClass { function doSomething() { echo $this->data; } } class Instantiated { var $data; function Instantiated($data) { $this->data = $data; StaticClass::doSomething(); } } $ob = new Instantiated('foo'); ?> This is rather confusing behavior - $this should be out of scope inside static methods no matter what. --------------------------------------------------------------------------- ATTENTION! Do NOT reply to this email! To reply, use the web interface found at http://bugs.php.net/?id=9005&edit=2

« previous php.dev (#48227) next »