Skip to content

Conversation

@LeoYang90
Copy link
Contributor

@LeoYang90 LeoYang90 commented May 20, 2017

this is a test for instance():

    public function testExtendReBindingInstance()
    {
        $_SERVER['_test_rebind'] = false;

        $container = new Container;
        $container->rebinding('foo',function (){
            $_SERVER['_test_rebind'] = true;
        });

        $obj = new StdClass;
        $container->instance('foo',$obj);

        $container->make('foo');

        $container->extend('foo', function ($obj, $container) {
            return $obj;
        });

        this->assertTrue($_SERVER['_test_rebind']);
    }

if we use instance() function to bind abstract, the rebinding() will be fired by extend().
However,
This is a test for bind():

    public function testExtendReBinding()
    {
        $_SERVER['_test_rebind'] = false;

        $container = new Container;
        $container->rebinding('foo',function (){
            $_SERVER['_test_rebind'] = true;
        });
        $container->bind('foo',function (){
            $obj = new StdClass;

            return $obj;
        });

        $container->make('foo');

        $container->extend('foo', function ($obj, $container) {
            return $obj;
        });

        this->assertFalse($_SERVER['_test_rebind']);
    }

If we use bind() function to bind abstract, the rebinding() will not be fired by extend() after make() function.
Container behaves differently from instance() and bind() about rebinding callback after using extend().
More detail in #19241

@LeoYang90 LeoYang90 closed this May 20, 2017
@LeoYang90 LeoYang90 reopened this May 20, 2017
@LeoYang90 LeoYang90 closed this May 20, 2017
@LeoYang90 LeoYang90 reopened this May 20, 2017
@LeoYang90 LeoYang90 closed this May 20, 2017
@LeoYang90 LeoYang90 reopened this May 20, 2017
@LeoYang90 LeoYang90 changed the title Container: Extend() can not fire the rebinding callback issue Container: Extend() can not fire the rebinding callback May 20, 2017
@LeoYang90 LeoYang90 changed the title Container: Extend() can not fire the rebinding callback [5.4] Container: Extend() can not fire the rebinding callback May 20, 2017
@taylorotwell taylorotwell merged commit 38c6076 into laravel:5.4 May 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.

2 participants