PHP 4.0 Bug #9005: Static classes sometimes have a $this pointer
| From: | chuck at horde dot org | Date: | Tue, 30 Jan 2001 18:39:15 +0000 |
| Subject: | PHP 4.0 Bug #9005: Static classes sometimes have a $this pointer | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-45407@lists.php.net to get a copy of this message | ||
From: chuck@horde.org
Operating system: Linux 2.2
PHP version: 4.0.4pl1
PHP Bug Type: Scripting Engine problem
Bug description: Static classes sometimes have a $this pointer
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.
--
Edit Bug report at: http://bugs.php.net/?id=9005&edit=1