Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@downace
Copy link
Contributor

@downace downace commented Jul 4, 2019

This fixes #674

\DI\value now can be used in \DI\Container::set to set raw values. This is useful when you need to set a Closure as raw value because by default Closures are interpreted as factories:

$container->set('foo', function() { return 'bar' }));
$container->get('foo'); // returns 'bar'

$container->set('foo', \DI\value(function() { return 'bar' })));
$container->get('foo'); // returns Closure

`\DI\value` could be used in `\DI\Container::set` to set raw values.
This is useful when you need to set a `Closure` as raw value because by
default `Closure`s are interpreted as factories:

```
$container->set('foo', function() { return 'bar' }));
$container->get('foo'); // returns 'bar'

$container->set('foo', \DI\value(function() { return 'bar' })));
$container->get('foo'); // returns Closure
```
@mnapoli mnapoli added the bug label Jul 8, 2019
@mnapoli
Copy link
Member

mnapoli commented Jul 8, 2019

Thank you this is perfect!

@mnapoli mnapoli merged commit 00a5eb0 into PHP-DI:master Jul 8, 2019
@downace downace deleted the 674-container-set-value-definition branch July 8, 2019 10:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

How to set a closure as value to compiled container?

2 participants