$this is defined when calling a static method from within an object
| From: | Chuck Hagenbuch | Date: | Wed, 03 Jan 2001 23:52:15 +0000 |
| Subject: | $this is defined when calling a static method from within an object | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-42894@lists.php.net to get a copy of this message | ||
While working on Mail_rfc822:: for PEAR, I came across the following scenario:
<?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 results in no errors of any kind and the output 'foo';
I would expect $this to be undefined inside static method calls; instead, it
seems to be defined to the $this pointer of the calling object, if you are
indeed calling from within an object.
Is this just a side effect? I think $this should be undefined inside all static
method calls (even if you call a method in the class - you might _want_ static
behavior sometimes), but I don't know how feasible that is, and I'm interested
what Zeev and co. have to say...
-chuck
--
Charles Hagenbuch, <chuck@horde.org>
"If you can't stand the heat, get out of the chicken!" - Baby Blues