Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#674 Special interpretation of `\DI\value` in `\DI\Container::set` #675

Merged
merged 1 commit into from Jul 8, 2019

Conversation

Projects
None yet
2 participants
@downace
Copy link
Contributor

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
#674 Special interpretation of `\DI\value` in `\DI\Container::set`
`\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

This comment has been minimized.

Copy link
Member

commented Jul 8, 2019

Thank you this is perfect!

@mnapoli mnapoli merged commit 00a5eb0 into PHP-DI:master Jul 8, 2019

2 checks passed

PrettyCI Code formatting
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details

@downace downace deleted the downace:674-container-set-value-definition branch Jul 8, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.