Re: PHP 4.0 Bug #9005: Static classes sometimes have a $this pointer
| From: | Chuck Hagenbuch | Date: | Wed, 31 Jan 2001 03:13:14 +0000 |
| Subject: | Re: PHP 4.0 Bug #9005: Static classes sometimes have a $this pointer | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-45418@lists.php.net to get a copy of this message | ||
Quoting "Arno A. Karner" <karner@tnss.com>:
> i dissagree $this in a static object should point to the default
> declared object,
> and if that is unacceptable because u want the the default data to be
> read only,
> then it should be allowed for methods at least.
It is unacceptable because it breaks all kinds of rules and expectations about
scope, and how objects work.
> but either way $this needs to be accessable in static functions or there
> not wothless but not worth as much as they could and should be
No. $this is - well, should be - meaningless in a static class. If an object
isn't instantiated, there is no $this. It should be that simple. Having static
class variables would be nice, but the current behavior is not a solution for
them.
To give a more concrete example of why the current behavior is bad, imagine
that you have a function that you'd like to be able to be call statically or
from within the object. If you call it statically, you want to instantiate an
object and then call the method on that object. The obvious way to figure out
whether or not you're in a static call is to check for the existance of $this.
But with the current behavior, you can't do that, because if you happen to be
calling the static method from within a _completely different_ object, $this
will be defined.
Note that the above confused the hell out of me for several hours as I tried to
figure out why Mail_RFC822::parseAddressList() suddenly stopped working when I
called it from within Mail::send().
-chuck
--
Charles Hagenbuch, <chuck@horde.org>
"My intuitive grasp of math often leads me astray." -Me