我是 PHP 声明的新手,我不明白如何在 ArrayObject 中有一个数组。以下代码正在运行(回显正常),但我有一些“SCREAM:忽略错误抑制”,因为“警告:在第 11 行从空值创建默认对象”和“警告:从空值创建默认对象” ...在第 13 行"
我愿意 :
$model = new stdClass();
$model->name = new stdClass();
$model->image = new ArrayObject();
$model->image->url = new stdClass();
$model->image->copyright = new stdClass();
$model->image->total = new stdClass();
$model->name = "France";
echo "Name : ".$model->name."<hr/>";
$model->image[0]->url = "/model1.jpg";
$model->image[0]->copyright = "Bellami";
$model->image[1]->url = "/model2.jpg";
$model->image[1]->copyright = "Bellami";
$model->image->total=2;
echo "Image 1 : ".$model->image[0]->copyright." - ".$model->image[0]->url."<hr/>";
echo "Image 2 : ".$model->image[1]->copyright." - ".$model->image[1]->url."<hr/>";
在我的情况下必须如何声明?