我试图理解new stdClass
在向函数发送数据方面,我创建了以下代码,我将得到一个错误,即说Warning: Creating default object from empty value
,但是,我仍然得到json数据。如何修复错误以及为什么我得到它?
$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);
}
结果看起来像这样,并且在我提到的结果下面有一个错误:
{"user":{"id":"12121212121"},"message":{"attachment":{"type":"file","image":"png"}}}
像这样为每个引用创建stdClass
$send = new stdClass();
$send->user=new stdClass();
$send->user->id = '12121212121';
$send->message=new stdClass();
$send->message->attachment=new stdClass();
$send->message->attachment->type = 'file';
$send->message->attachment->image = 'png';
$res = process($send);
function process($send){
$data = json_encode($send);
print_r($data);
}