【发布时间】:2019-09-03 05:44:10
【问题描述】:
- Laravel 版本:5.8.11
- PHP 版本:7.1.26 (Homestead) - 但也使用 7.2 进行了测试,结果相同
自从从 5.7 更新到 5.8 后,我无法再解析实例了。它返回一个字符串,我得到Trying to get property of non-object。
复制步骤:
我将实例绑定在中间件中:
$globals = new Globals();
app()->instance('App\Helpers\Globals', $globals);
$globals->brows_browser = Agent::browser();
稍后尝试解决它时(例如在 web.php 中):
$browser = resolve('App\Helpers\Globals')->brows_browser;
我收到错误异常Trying to get property of non-object。 $browser 是一个字符串“Helpers\Globals”,而不是一个对象。之前在所有 Laravel 版本中都可以正常工作。
namespace App\Helpers;
class Globals
{
public $brows_browser;
public $brows_device;
public $brows_platform;
public $brows_version;
}
我也尝试在路由(web.php)中绑定实例,结果相同。
当我查看resolve('App\Helpers\Globals') 时,它是一个字符串“App\Helpers\Globals”,而不是一个对象。
有人知道吗?这可能是 L5.8 中的错误吗?
谢谢
更新:
这不是错误。
我安装了 goetas-webservices/xsd2php-runtime 和作曲家,这导致了问题。不过,我真的不知道为什么以及该怎么做。
这些是安装的依赖项。因为我需要那个包,所以我有点走投无路:
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
更新 2:
我进一步深入研究,似乎 hoa/compiler(特别是 hoa/stream)与 Laravel 5.8 不兼容
hoa/compiler 是 jms/serializer 的依赖。
这真的很糟糕,因为 jms/serializer 对我们来说是不可替代的!
【问题讨论】:
-
如果您在绑定后尝试解决它会发生什么?
-
我已经试过了。同样的错误。
-
你确定没有代码覆盖
$browser吗?你是更新了 PHP 还是只更新了 Laravel?