Re: [RFC] Callable constructors
| From: | Adam Harvey | Date: | Thu, 25 Feb 2016 18:16:56 +0000 |
| Subject: | Re: [RFC] Callable constructors | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-91413@lists.php.net to get a copy of this message | ||
On 25 February 2016 at 08:44, Dan Ackroyd <danack@basereality.com> wrote:
> I use the Auryn* DIC library. What I've wanted to do, and should be
> able to do in my opinion, is this:
>
> $injector->delegate('FooInterface', 'FooImplementation::__construct');
I only skimmed the RFC (and am unfamiliar with Auryn beyond glancing
at its documentation for about ten seconds just now), but am I right
that this is equivalent to the following?
$injector->delegate('FooInterface', function (...$args) { return new
FooImplementation(...$args); });
If that's the case, I'm not really convinced that this is worth the
syntactic sugar. I'm also somewhat concerned about conflating
instantiation and method calls — although they both ultimately call a
method, they're not actually the same thing, since instantiating an
object does extra work at the same time. Being able to just look for
"new" in code is helpful.
Open to being convinced otherwise (examples from other languages would
be helpful), but my initial reaction isn't really positive.
Thanks,
Adam