Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:91434 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 82932 invoked from network); 26 Feb 2016 11:30:32 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 26 Feb 2016 11:30:32 -0000 X-Host-Fingerprint: 178.62.40.5 ajf.me Received: from [178.62.40.5] ([178.62.40.5:22418] helo=localhost.localdomain) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id E6/23-55238-85730D65 for ; Fri, 26 Feb 2016 06:30:32 -0500 Message-ID: To: internals@lists.php.net References: Date: Fri, 26 Feb 2016 11:30:27 +0000 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:42.0) Gecko/20100101 Firefox/42.0 SeaMonkey/2.39 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Posted-By: 178.62.40.5 Subject: Re: [PHP-DEV] [RFC] Callable constructors From: ajf@ajf.me (Andrea Faulds) Hi Dan, Dan Ackroyd wrote: > On 25 February 2016 at 18:16, Adam Harvey wrote: >> >> am I right >> that this is equivalent to the following? >> >> $injector->delegate('FooInterface', function (...$args) { return new > FooImplementation(...$args); }); > > Nope. > > The vital part you missed is that with the original function, all of > the parameters (aka dependencies of the class) can be found through > reflection, and so can be created by the injector as needed. By using > function (...$args){} - all of the parameter information is lost, and > so isn't usable by an autowiring-injector. This is true for a trivial implementation like the one above, but I would point out that a more sophisticated userland implementation could fix this by generating PHP code. So it's still worth questioning whether this needs to be a built-in function. Thanks! -- Andrea Faulds https://ajf.me/