Re: RFC: Custom Factories (SPL)

From: Date: Thu, 19 Nov 2009 07:51:16 +0000
Subject: Re: RFC: Custom Factories (SPL)
References: 1 2 3 4 5  Groups: php.internals 
Request: Send a blank email to internals+get-46097@lists.php.net to get a copy of this message
Eloy Bote Falcon a écrit :
2009/11/18 Mathieu Suen <mathieu.suen@easyflirt.com>
Etienne Kneuss a écrit : Hello,
On Wed, Nov 18, 2009 at 5:54 PM, Mathieu Suen <mathieu.suen@easyflirt.com
wrote:
Robert Lemke a écrit :
Hi folks,
after discussing the idea with various PHP developers I now felt safe enough that it's not a completely stupid idea to post an RFC for it. The idea is to add support the registration of custom factories which are responsible for instantiating certain classes. Here is the first draft of my RFC: http://wiki.php.net/rfc/customfactories I suggest that we first discuss the implications and usefulness of this feature. In a second step I'd need to find some skilled internals wizard who can implement it, because not being a C developer myself, all I can offer is making suggestions and fine coffee. Looking forward to hearing your comments! Robert An other way maybe to allow this:
$email = new $emailClassName(); This is already allowed.
Best,
Right!! I get confused with: $classNamme::getInstance(); So you can easily inject dependency: class Foo {
       protected $emailer;
       public function __construct($emailClass) {
               $this->emailer= $emailClass;
       }
       public function bar() {
               // $email = new $this->emailer(); Of course not allowed
               $emailer = $this->emailer;
               $email = $emailer();
               // ...
       }
} -- Mathieu Suen
Well, $email = new $this->emailer(); it's allowed too, and behaves as expected since FOO::emailer it's a string.
I have tested in php 5.2 is that a feature added in 5.3?
Reagards, Eloy Bote.
-- • *Mathieu Suen* | It Team | www.easyflirt.com • mathieu [dot] suen [at] easyflirt [dot] com • EasyFlirt - Park Nord, Les Pléiades, 74370 - Metz-Tessy - FRANCE • Pensez à l'environnement, n'imprimez cet e-mail qu'en cas de réelle nécessité

« previous php.internals (#46097) next »