Re: [RFC] Callable constructors
| From: | Andrea Faulds | Date: | Fri, 26 Feb 2016 11:30:27 +0000 |
| Subject: | Re: [RFC] Callable constructors | ||
| References: | 1 2 3 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-91434@lists.php.net to get a copy of this message | ||
Hi Dan,
Dan Ackroyd wrote:
On 25 February 2016 at 18:16, Adam Harvey <adam@adamharvey.name> wrote: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/am I right that this is equivalent to the following? $injector->delegate('FooInterface', function (...$args) { return newFooImplementation(...$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.