[5.8] Can't resolve instance from service container

Posted 1 month ago by elasticsteve
  • Laravel Version: 5.8.11
  • PHP Version: 7.1

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;

}

Anyone any idea why? Thanks!

Please sign in or create an account to participate in this conversation.

Reply to

Use Markdown with GitHub-flavored code blocks.