thephpleague / container

Small but powerful dependency injection container
http://container.thephpleague.com
MIT License
843 stars 102 forks source link

References are unallowed #212

Closed hakuno closed 3 years ago

hakuno commented 4 years ago

Hey! How are you?

I can't pass any parameter by reference in my constructors through container. I got something like:

Parameter expected to be a reference, value given.

So I looked at league/container/src/Definition/Definition.php on line 252 and see around... I've no clue though.

Are the arguments cloned or "proxied"? How can I overcome this?

Any option such as

$container->add('teste', App/Teste::class)->addArgumentByReference($hey);

???

philipobenito commented 3 years ago

What is it you're actually trying to retrieve here? If you're passing an object it is always reference anyway, if you're passing it to multiple places, the reference object should be added to the container with share so doesn't build a new one each time.

Will close as this is more of s discussion, feel free to continue the discussion.