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] Container:Extend and Rebinding bug or feature? #19241

Closed
LeoYang90 opened this issue May 17, 2017 · 1 comment
Closed

[5.4] Container:Extend and Rebinding bug or feature? #19241

LeoYang90 opened this issue May 17, 2017 · 1 comment

Comments

@LeoYang90
Copy link
Contributor

LeoYang90 commented May 17, 2017

  • Laravel Version: 5.4.23
  • PHP Version:7.1
  • Database Driver & Version:NA

Hi,
Recently, I am learning the source code of container, there is something that I can not figure out whether it is a bug or a feature:

Description:

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;
        });

        PHPUnit_Framework_Assert::assertFalse($_SERVER['_test_rebind']);
    }

If we use bind() function to bind abstract, the rebinding() will not be fired by extend() after make() function.
However,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;
        });

        PHPUnit_Framework_Assert::assertTrue($_SERVER['_test_rebind']);
    }

if we use instance() function to bind abstract, the rebinding() will be fired by extend().

So extend() will have different affect on rebinding() under bind() and instance(), is it reasonable?

@themsaid
Copy link
Member

I'm sorry but this is not the right place for such questions, please use the forums, I'm sure people will help you there.

taylorotwell pushed a commit that referenced this issue May 24, 2017
* fix:Extend() can not fire the rebinding callback issue #19241

* StyleCI

* StyleCI

* StyleCI
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

No branches or pull requests

2 participants