theother1
theother1

Reputation: 41

Laravel 5.8 - Can't resolve instance from service container after update from 5.7 to 5.8

Since updating from 5.7 to 5.8, I can't resolve an instance anymore. It returns a string and I get Trying to get property of non-object.

Steps To Reproduce:

I bind the instance in a Middleware with:

$globals = new Globals();
app()->instance('App\Helpers\Globals', $globals);
$globals->brows_browser = Agent::browser();

when trying to resolve it later (for example in web.php) with:

$browser = resolve('App\Helpers\Globals')->brows_browser;

I get an error exception Trying to get property of non-object. $browser is a string "Helpers\Globals" and not an object. Was working fine in all Laravel versions before.

namespace App\Helpers;

class Globals
{
    public $brows_browser;
    public $brows_device;
    public $brows_platform;
    public $brows_version;
}

I also tried to bind the instance in the route (web.php) and it produced the same result.

When I look at resolve('App\Helpers\Globals'), it is a string "App\Helpers\Globals" and not an object.

Anyone any idea? Could this be a bug in L5.8?

thanks

UPDATE:

It is not a bug. I have goetas-webservices/xsd2php-runtime installed with composer and that's causing problems. I really have no idea why and what to do about it though.

These are the dependencies installed. I'm a bit at a dead end as I need that package:

Package operations: 17 installs, 0 updates, 0 removals
  - Installing jms/metadata (2.0.0): Loading from cache
  - Installing hoa/exception (1.17.01.16): Loading from cache
  - Installing hoa/event (1.17.01.13): Loading from cache
  - Installing hoa/consistency (1.17.05.02): Loading from cache
  - Installing hoa/zformat (1.17.01.10): Loading from cache
  - Installing hoa/protocol (1.17.01.14): Loading from cache
  - Installing hoa/iterator (2.17.01.10): Loading from cache
  - Installing hoa/visitor (2.17.01.16): Loading from cache
  - Installing hoa/ustring (4.17.01.16): Loading from cache
  - Installing hoa/compiler (3.17.08.08): Loading from cache
  - Installing hoa/regex (1.17.01.13): Loading from cache
  - Installing hoa/math (1.17.05.16): Loading from cache
  - Installing hoa/stream (1.17.02.21): Loading from cache
  - Installing hoa/file (1.17.07.11): Loading from cache
  - Installing doctrine/annotations (v1.6.1): Loading from cache
  - Installing jms/serializer (2.2.0): Loading from cache
  - Installing goetas-webservices/xsd2php-runtime (v0.2.9): Loading from cache
jms/serializer suggests installing doctrine/collections (Required if you like to use doctrine collection types as ArrayCollection.)
Writing lock file

UPDATE 2:

I drilled further down and it seems that hoa/compiler (specifically hoa/stream) is incompatible with Laravel 5.8

hoa/compiler is a dependency of jms/serializer.

That really sucks because jms/serializer is irreplaceable for us!

Upvotes: 3

Views: 672

Answers (2)

theother1
theother1

Reputation: 41

It's not a Laravel bug but an incompatibility with hoa/compiler (specifically hoa/stream).

hoa/compiler is a dependency of jms/serializer.

So for the moment jms/serializer won't play nice with Laravel 5.8

Upvotes: 1

Mahdi Bahari
Mahdi Bahari

Reputation: 109

simple bind like this in laravel 5.8 take care will be registered within service providers,

$this->app->bind('App\Helpers\Globals', function () {
   return new App\Helpers\Globals();
});

You may use the make

$globals = $this->app->make('App\Helpers\Globals');

Upvotes: 0

Related Questions