如何修复新的stdClass错误

时间:2017-12-28 10:57:53

标签: php stdclass

我试图理解new stdClass在向函​​数发送数据方面的问题,我创建了以下代码,并且我会收到错误消息{{1但是,我仍然可以获得json数据。如何修复错误以及为什么我会收到错误?

Warning: Creating default object from empty value

结果看起来像这样,并且在我提到它之前有一个错误高于结果:

$send = new stdClass(); $send->user->id = '12121212121'; $send->message->attachment->type = 'file'; $send->message->attachment->image = 'png'; $res = process($send); function process($send){ $data = json_encode($send); print_r($data); }

1 个答案:

答案 0 :(得分:2)

为每个引用创建stdClass,如此

<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<!-- Optional theme -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css">
<!-- Latest compiled and minified JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" ></script>