从PHP中的空值创建默认对象?只有在将PHP环境升级到PHP5.4及更高版本之后,我才会看到此错误。错误指向这一行代码:错误:从空值创建默认对象代码:$res->success = false;我首先需要声明我的$res反对?
3 回答
繁星淼淼
TA贡献1775条经验 获得超11个赞
E_STRICT
error_reporting
error_reporting
E_WARNING
$res
NULL
$res = NULL;$res->success = false; // Warning: Creating default object from empty value
$res
$res = 33;$res->success = false; // Warning: Attempt to assign property of non-object
E_STRICT
E_WARNING
success
$res
stdClass
$res = new \stdClass();$res->success = false;
牧羊人nacy
TA贡献1862条经验 获得超7个赞
E_STRICT
E_WARNING
E_WARNING
if (!isset($res)) $res = new stdClass();$res->success = false;
呼如林
TA贡献1798条经验 获得超3个赞
$res = (object)array("success"=>false); // $res->success = bool(false);
$res = (object)array(); // object(stdClass) $res = new stdClass(); // old method
$res->success = !!0; // bool(false) $res->success = false; // bool(false) $res->success = (bool)0; // bool(false)
- 3 回答
- 0 关注
- 904 浏览
添加回答
举报
0/150
提交
取消