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

[5.4] Use Instance instead of Deferred Provider #20714

Merged

Conversation

Hariador
Copy link
Contributor

When calling app()->instance('foo','bar'), if there's a deferred service provider registered for class foo,
the deferred provider gets called and overrides the instance that was just set. This means that if you have

app()->bind('foo','foo); // in a deferred service provider

and you run the following as the first reference to 'foo'

app()->instance('foo','bar');
$instance = app()->make('foo');

$instance = 'foo' instead of 'bar'

Added an additional condition to Application->make to check to see if an instance for that $abstract as already been set and skip loading the deferred provider if it does.

This issue tends to crop up most when writing tests, since the call to app()->instance is likely the first time the container will have to resolve the binding and overriding a binding with a particular instance of a Mock is common.

jreichert-bold and others added 2 commits August 23, 2017 17:55
When calling app()->instance('foo','bar'), if there's a deferred service provider registered for class foo,
the deferred provider gets called and overrides the instance that was just set.  This means that if you have

app()->bind('foo','foo); // in a deferred service provider

and you run the following as the first reference to 'foo'

app()->instance('foo','bar');
$instance = app()->make('foo');

$instance = 'foo' instead of 'bar'

Added an additional condition to Application->make to check to see if an instance for that $abstract as already been set and skip loading the deferred provider if it does.
@tillkruss tillkruss changed the title Use Instance instead of Deferred Provider [5.4] Use Instance instead of Deferred Provider Aug 24, 2017
@taylorotwell taylorotwell changed the base branch from 5.4 to master August 24, 2017 19:12
@taylorotwell taylorotwell merged commit 9a32fb5 into laravel:master Aug 24, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants