貌似php8 不能stdClass直接赋予User类了吗

smart

问题描述

$this->user = json_decode($result);
在php7.4是正常的,php8.2就报错这个错误:Cannot assign stdClass to property app\api\controller\v1\Base::$user

156 1 0
1个回答

jack10082009

不支持对象类型隐式转换。
你可以序列化再反序列化曲线救国。
例如之前在PHP5.6的时代经常能看见这样的代码json_decode(json_encode($data),true);

  • 暂无评论
×
🔝