5
  • 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!

user2928048
  • 3,940
  • 2
  • 12
  • 12

3 Answers3

4

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.

Taurai Benhura
  • 141
  • 1
  • 4
0

Workaround

Change in getAlias() function ! isset($this->aliases[$abstract]) for ! isset($this->aliases[(string)$abstract])

Or change explicitly type-hint to string at ALL functions (@param string is not enough) public function getAlias($abstract) for public function getAlias(string $abstract)

But it fails later in next use of [$abstract] in Container: isShared() at isset($this->instances[(string)$abstract]) isset($this->bindings[(string)$abstract] resolve() calling to$this->resolved[(string)$abstract] = true; getConcrete() at if (isset($this->bindings[(string)$abstract])) getContextualConcrete() at if (empty($this->abstractAliases[(string)$abstract])) getExtenders() at if (isset($this->extenders[(string)$abstract])) and in Illuminate\Foundation\Application: make() at if (isset($this->deferredServices[(string)$abstract]) && ! isset($this->instances[(string)$abstract]))

PS: Please have a look to Alvaro Gonzalez's comment in php - How do I fix this illegal offset type error

user2928048
  • 3,940
  • 2
  • 12
  • 12
0

I finally found out the issue was send params like ::class which can not be used as an array index. Strings must be instead

user2928048
  • 3,940
  • 2
  • 12
  • 12