编程语言
首页 > 编程语言> > php – CodeIgniter – 从空值创建默认对象

php – CodeIgniter – 从空值创建默认对象

作者:互联网

A PHP Error was encountered

Severity: Warning

Message: Creating default object from empty value

Filename: models/Modeltest.php

Line Number: 13

我试图在模型中创建一个数组并将其返回给控制器,但它是否给出了这个警告?任何人都可以帮我解决问题吗?

我的ModelClass代码

    $list = Array();
    $list[0]->title = "first blog title";
    $list[0]->author = "author 1";

    $list[1]->title = "second blog title";
    $list[1]->author = "author 2";

    return $list;

我的控制器类代码

    $this->load->model("modeltest");
    print_r($this->modeltest->get_articles_list());

解决方法:

我相信你想要这样的东西:

$list = array();
$list[0] = new stdClass;
$list[0]->title = "first blog title";
$list[0]->author = "author 1";
$list[1] = new stdClass;
$list[1]->title = "second blog title";
$list[1]->author = "author 2";

但为什么不将数组用作数组呢?

$list = array();
$list[0]['title'] = "first blog title";
$list[0]['author'] = "author 1";

标签:notice,php-5-4,php,codeigniter,warnings
来源: https://codeday.me/bug/20190725/1529225.html