diff --git a/src/Illuminate/Container/Container.php b/src/Illuminate/Container/Container.php index 205b1beb32bc..94f426c0dc2c 100755 --- a/src/Illuminate/Container/Container.php +++ b/src/Illuminate/Container/Container.php @@ -234,6 +234,10 @@ public function bind($abstract, $concrete = null, $shared = false) // bound into this container to the abstract type and we will just wrap it // up inside its own Closure to give us more convenience when extending. if (! $concrete instanceof Closure) { + if (! is_string($concrete)) { + throw new \TypeError(self::class.'::bind(): Argument #2 ($concrete) must be of type Closure|string|null'); + } + $concrete = $this->getClosure($abstract, $concrete); } diff --git a/tests/Container/ContainerTest.php b/tests/Container/ContainerTest.php index 7aa77ba1cd49..13361beb1380 100755 --- a/tests/Container/ContainerTest.php +++ b/tests/Container/ContainerTest.php @@ -120,6 +120,15 @@ public function testSharedConcreteResolution() $this->assertSame($var1, $var2); } + public function testBindFailsLoudlyWithInvalidArgument() + { + $this->expectException(\TypeError::class); + $container = new Container; + + $concrete = new ContainerConcreteStub(); + $container->bind(ContainerConcreteStub::class, $concrete); + } + public function testAbstractToConcreteResolution() { $container = new Container;