On 25 February 2016 at 18:16, Adam Harvey <a...@adamharvey.name> 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.

The only equivalent thing that would be to either create a dumb
function by hand:

function createFooImpl(Bar $bar, Quux $quux) {
    return new FooImplementation($bar, $quux);
}

for every possible constructor used in your app (and remember to keep
it up to date of course!), or to use eval to create a function on the
fly.

> "I only skimmed the RFC"

I find this very dissapointing. Conversations are far more productive
if people have read the whole of a proposal before deciding how they
feel about it and giving feedback.

In particular reading the sections "Can't be used as strings in class
properties" and "Can't be used in string based configuration" would
give examples where the RFC is of benefit in a way that is not related
to DIC libraries.

cheers
Dan

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to