警告:从空值创建默认对象(典型解决方案不能解决问题) [英] Warning: Creating default object from empty value (typical solution not solving issue)

查看:58
本文介绍了警告:从空值创建默认对象(典型解决方案不能解决问题)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

注意:我已阅读有关如何解决此问题的有关 stackoverflow 的其他主题:在 PHP 中从空值创建默认对象?

NOTE: I've read the other topics on stackoverflow about how to solve this issue: Creating default object from empty value in PHP?

出于某种原因,我仍然收到警告消息:Creating default object from empty value

For some reason I still get the Warning message: Creating default object from empty value

我尝试了一些方法来修复警告:

I've tried a few things to fix the warning:

$data = new stdClass();
$data->result->complex->first_key = $old_data->result->complex;

也尝试过:

$data->result->complex = new stdClass();
$data->result->complex->first_key = $old_data->result->complex;

仍然收到警告:Creating default object from empty value 在上面 new stdClass() 初始化的行号上.

Still get the warning: Creating default object from empty value on the line number of the new stdClass() initialization above.

预期结果:如何正确初始化新的空对象?

Desired Outcome: How can I properly initialize the new empty object?

推荐答案

如果您想避免警告,您需要预先创建每个级别:

If you want to avoid the warning you'll need to pre-create each level:

$data = new stdClass();
$data->result = new stdClass();
$data->result->complex = new stdClass();
$data->result->complex->first_key = $old_data->result->complex;

这篇关于警告:从空值创建默认对象(典型解决方案不能解决问题)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆