Re: [PHP-DEV] Traits and static methods

2010-11-22 Thread Stefan Marr
Hi Simas: On 22 Nov 2010, at 13:47, Simas Toleikis wrote: > Would it work if instance is saved inside a local static var like: > > public static function getInstance() { > > static $instance = NULL; > > if (is_null($instance)) { >$instance = new self(); > } > > return $instance; > } ht

Re: [PHP-DEV] Traits and static methods

2010-11-22 Thread Simas Toleikis
Hi Sebastian, This is not really a good example as the getInstance() method alone is > not sufficient for a reusable implementation of the Singleton pattern. > Yes, it was just a pseudo-code and not a true singleton implementation. > A trait for a reusable implementation of the Singleton pa

Re: [PHP-DEV] Traits and static methods

2010-11-22 Thread Sebastian Bergmann
Am 16.11.2010 18:46, schrieb Simas Toleikis: > p.s. a Singleton-Trait implementation could look like: > > trait Singleton { > public static function getInstance() { ... } > } > > class Child extends Parent { > use Singleton; > } > > Child::getInstance(); This is not really a good example a

Re: [PHP-DEV] Traits and static methods

2010-11-17 Thread Stefan Marr
Hi Simas: Thanks for sending me the test cases. I checked them in, and surprise surprise: it actually was already completely implemented. I didn't had to touch any code... So the missing bit was being more explicit in the RFC. I added a section and an example based on your Singleton code. Now I

Re: [PHP-DEV] Traits and static methods

2010-11-16 Thread Stefan Marr
Hi Simas: On 17 Nov 2010, at 07:32, Simas Toleikis wrote: > Alright then, I am sure someone will find more uses for static methods in > Traits like factories/utilities (especially if traits can be made to work > with late static binding). > > I assume this will be implemented in one way or anothe

Re: [PHP-DEV] Traits and static methods

2010-11-16 Thread Simas Toleikis
Hi Ferenc, for reusable singleton pattern with php 5.3 > http://www.slideshare.net/fabpot/design-patternrevisitedphp53 > slide 11 and 12 > As Tom already pointed out - there is that lock-down of your parent(s) to singletons with this type of implementation and there are other shortcomings when u

Re: [PHP-DEV] Traits and static methods

2010-11-16 Thread Simas Toleikis
Hi Stefan, Following the motto 'it is just compiler assisted copy and paste' I think > it should be implemented. > Alright then, I am sure someone will find more uses for static methods in Traits like factories/utilities (especially if traits can be made to work with late static binding). I ass

Re: [PHP-DEV] Traits and static methods

2010-11-16 Thread Tom Sartain
On Tue, Nov 16, 2010 at 3:55 PM, Ferenc Kovacs wrote: > > for reusable singleton pattern with php 5.3 > http://www.slideshare.net/fabpot/design-patternrevisitedphp53 > slide 11 and 12 > > Tyrael > The problem with the solution presented in the slides is that it limits every singleton class to onl

Re: [PHP-DEV] Traits and static methods

2010-11-16 Thread Ferenc Kovacs
On Tue, Nov 16, 2010 at 6:46 PM, Simas Toleikis wrote: > Hello, > > I was just skimming through Traits RFC document on the wiki trying to find > a > practical use for them. The first thing that comes to my mind is a > Singleton > implementation - this is where I found myself literally "copying" m

Re: [PHP-DEV] Traits and static methods

2010-11-16 Thread Stefan Marr
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