Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:46102 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 71371 invoked from network); 19 Nov 2009 14:48:46 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 19 Nov 2009 14:48:46 -0000 Authentication-Results: pb1.pair.com header.from=ionut.g.stan@gmail.com; sender-id=pass; domainkeys=bad Authentication-Results: pb1.pair.com smtp.mail=ionut.g.stan@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.220.227 as permitted sender) DomainKey-Status: bad X-DomainKeys: Ecelerity dk_validate implementing draft-delany-domainkeys-base-01 X-PHP-List-Original-Sender: ionut.g.stan@gmail.com X-Host-Fingerprint: 209.85.220.227 mail-fx0-f227.google.com Received: from [209.85.220.227] ([209.85.220.227:59244] helo=mail-fx0-f227.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 37/11-65535-BCA550B4 for ; Thu, 19 Nov 2009 09:48:46 -0500 Received: by fxm27 with SMTP id 27so2537039fxm.23 for ; Thu, 19 Nov 2009 06:48:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from :user-agent:mime-version:to:cc:subject:references:in-reply-to :content-type:content-transfer-encoding; bh=hyDUnYq+BC9UDLfDbo+/cHz5r5W4sPRSRm6/5hLf8Wc=; b=itckr2gVKOFzDC1q9ELK4p4/MaCgub+zxnyKfgJPMg7DhqZwLyCauwr2IyUpCZgYCE M+ab8KbCX1U18gzIXc1G/12DpKNjSkEWX/vIlJQBDKES8L7Hkatpopdits1rHqA79S4P FhgtCC8NMJfWcAPun5mAxh72UhMUtP57G9iGw= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:user-agent:mime-version:to:cc:subject :references:in-reply-to:content-type:content-transfer-encoding; b=iapg63X5YhUzpZZ/NDMDI9b7Ua4aGL1jDFXDZt64oJluy4sFFFN2G/MZA+ou/HsqvQ bJmkVfYfPgWiPRSwlHdPa3f5ZjYLPibAdQdXx6JLkBo27b0b6S2ibRMkZXepmWodTkIC DUKlIDJ9drveipOgjOf2/CJZvrG0nSxX/kjLk= Received: by 10.204.33.193 with SMTP id i1mr84577bkd.75.1258642119864; Thu, 19 Nov 2009 06:48:39 -0800 (PST) Received: from ?192.168.10.112? ([82.208.177.66]) by mx.google.com with ESMTPS id 14sm157876bwz.13.2009.11.19.06.48.36 (version=TLSv1/SSLv3 cipher=RC4-MD5); Thu, 19 Nov 2009 06:48:36 -0800 (PST) Message-ID: <4B055ABE.9020902@gmail.com> Date: Thu, 19 Nov 2009 16:48:30 +0200 User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.1.4pre) Gecko/20090915 Thunderbird/3.0b4 MIME-Version: 1.0 To: Robert Lemke CC: internals@lists.php.net References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] RFC: Custom Factories (SPL) From: ionut.g.stan@gmail.com ("Ionut G. Stan") This smells like metaclasses to me, just that in your RFC they are supposed to work on a global level, not on a per class level. Python, for example, has a magic method called `__new__`, which controls the creation of the object whenever a new class is instantiated. It actually allows you to return a different object than the expected one. I somehow like the proposal, but it may create havoc in some code bases. I wouldn't really want to see `new FooBar`, when it actually means a `DamnBar`. There are also other things to take into consideration. You may want to override this instantiation mechanism for `FooBar` just in a single class, not in all of them, which complicates the problem. You'd have to received the scope where the instantiation is done, but even then, there may be no way to really know which *object*, not class, wants to instantiate `FooBar`. I agree IoC is necessary, but I'm not really sure this is the way to go. ... [some thinking] At this point, in PHP, classes are global constant symbols. Allowing us to override the instantiation mechanism would make them global variable symbols. The below example is already possible in PHP and I believe it already does what you're asking for (in the current RFC): class Emailer {} $Emailer= 'Emailer'; class FooBar { public function sendEmail() { global $Emailer; $emailer = new $Emailer; } } On 11/18/2009 6:06 PM, Robert Lemke wrote: > 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 > -- Ionut G. Stan I'm under construction | http://blog.igstan.ro/