Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Container::getAlias($abstract) throws ErrorException: Illegal offset type in isset or empty when $abstract there is not in $this->aliases[]

Tags:

  • Laravel Version: 5.6.16
  • PHP Version: 7.2.3
  • Database Driver & Version: N/A

Description:

laravel\framework\src\Illuminate\Container\Container.php public function getAlias($abstract) throws ErrorException: Illegal offset type in isset or empty when $abstract there is not in $this->aliases[]

$this->aliases[$abstract] is null and !isset($this->aliases[$abstract]) throws ErrorException: Illegal offset type in isset or empty

$abstract value is Modules\Administration\Tests\Commands\StubJsonCommandHandler

Steps To Reproduce:

Run AdministrationControllerTest (https://github.com/proyectotau/TAU/ clone laraveldusk branch [4ef9b0e124657abed7afde0969f332bf7be95a8b])

Is it a bug or I have any mistake? Thanks in advance!

like image 211
user2928048 Avatar asked May 06 '18 18:05

user2928048


1 Answers

When binding an instance to the container, please make sure you are using:

app()->instance('dependency', $instantiation);

not,

app()->bind('dependency', $instantiation); // DON'T bind an instance

Attempting to bind an instance will result an error, as the container tries to index possible aliases using a concrete object as opposed to a type.

like image 68
Taurai Benhura Avatar answered Sep 18 '22 12:09

Taurai Benhura