Re: $this->value VS $value
| From: | Jochem Maas | Date: | Tue, 23 Sep 2008 22:25:30 +0000 |
| Subject: | Re: $this->value VS $value | ||
| References: | 1 2 3 4 5 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-280802@lists.php.net to get a copy of this message | ||
Nathan Nobbe schreef:
On Tue, Sep 23, 2008 at 10:41 AM, Micah Gersten <micah@onshore.com> wrote:Nathan is correct, I'd like to add that 'self' is actually nothing more than a simple alias used at compile time to put the class name in ... 'self' literally equates to 'MyClass', but it saves hassle when refactoring and it's much clearer that you mean 'this class Im looking at/working in' .... personally whenever I see a classname referenced statically inside a method I kind of assume it must be another class :-P ... now had 'self' been late (statically) bound ... no I won't go there, we get 'static' very soon now :-PEric Butera wrote:yea, php will think its a local variable if not qualified w/ the self keyword and scope resolution (or w/e its called in php :D), but the name of the class and the scope resolution operator works as well. its just a hair less flexible because if the class name changes you have to update some code whereas w/ self, the code is no longer dependent upon the class name. /// psuedocode ! class A { protected static $someStatic = 5; public function doStuff() { $someStatic // php thinks this is a local var self::$someStatic // php can id this as a static var A::$someStatic // php can id this as a static varOn Tue, Sep 23, 2008 at 12:26 PM, Jochem Maas <jochem@iamjochem.com>wrote:Actually within a class, I think you must self:: before a static property or something shows up in the error log.(using $this->foo or MyClass::$foo for static properties).also self::
} -nathan