Re: Traits and static methods
| From: | Stefan Marr | Date: | Tue, 16 Nov 2010 20:21:14 +0000 |
| Subject: | Re: Traits and static methods | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-50267@lists.php.net to get a copy of this message | ||
Hi Simas:
On 16 Nov 2010, at 18:46, Simas Toleikis wrote:
> The first thing that comes to my mind is a Singleton
> implementation - this is where I found myself literally "copying" most of
> the code in the past. As far as I know there is no way to implement this
> pattern properly in PHP without duplicate code (due to lack of multiple
> inheritance/templating).
>
> Unfortunately, the same RFC document mentions this for trait methods:
>
> The static modifier is not supported, because it would change the methods
>> semantics and references to $this would break.
>>
>
> .. and that pretty much defeats Singleton-Trait implementation. Is there any
> particular technical/design reasons why traits can't handle $this inside
> static methods just like regular static methods do (with a fatal error)?
Hm, good question. I don't recall any implementation details. Haven't touched the code for
too long.
From the top of my head, I don't see why it should not work.
If I would have elaborated a bit more what I was thinking when I wrote that comment...
Following the motto 'it is just compiler assisted copy and paste' I think it should be
implemented.
Best regards
Stefan
--
Stefan Marr
Software Languages Lab
Vrije Universiteit Brussel
Pleinlaan 2 / B-1050 Brussels / Belgium
http://soft.vub.ac.be/~smarr
Phone: +32 2 629 2974
Fax: +32 2 629 3525