Re: Class::__construct() vs. $this->__construct()
| From: | Nikolas 'Atrus' Coukouma | Date: | Wed, 30 Mar 2005 23:17:58 +0000 |
| Subject: | Re: Class::__construct() vs. $this->__construct() | ||
| References: | 1 2 3 4 5 | Groups: | php.pear.dev |
| Request: | Send a blank email to pear-dev+get-37008@lists.php.net to get a copy of this message | ||
Hans L wrote:
>> I know that $this is still available when making a static call on an
>> instantiated class in PHP 4, but my understanding is:
>>
>> - It's Bad(tm), in the same way returning from a constructor is Bad(tm).
>> - It's ambiguous; if you have 3 instances, which one does $this point
>> at?
>> - It doesn't work in PHP 5 (or won't work in a future version)
>
>
> Yeah, it doesn't work in PHP5 -- since 5.0.0 or earlier AFAIR. You
> also cannot call a non-static method statically in PHP5, but that's a
> little less related. :)
>
> -Hans
>
This merits some clarification. The example does, in fact, work in PHP5.
Using $this in a static context does cause an error. However, PHP has
this obsession with namespaces and having lots of them ...
Demo (it's a bit long):
http://zaphod.student.umd.edu/~atrus/namespace_weirdness.php
http://zaphod.student.umd.edu/~atrus/namespace_weirdness.phps
-Nikolas 'Atrus' Coukouma