未定义的属性stdClass

时间:2019-05-07 14:04:49

标签: php

为什么??

  

遇到PHP错误严重性:注意

     

消息:未定义的属性:stdClass :: $ users

     

文件名:views / user_view.php

     

行号:10

     

回溯:

     

文件:C:\ xampp \ htdocs \ ci \ application \ views \ user_view.php行:10   功能:_error_handler

     

文件:C:\ xampp \ htdocs \ ci \ application \ controllers \ users.php行:7   功能:查看

     

文件:C:\ xampp \ htdocs \ ci \ index.php行:315功能:require_once

1 个答案:

答案 0 :(得分:1)

您尝试访问未首先定义的变量。如果先定义,就不会出错。

<?php

$x = new stdClass();
$y = $x->z;   // gererates Notice in error_log


$x = new stdClass();
$x->z = 'assigned';    // now it is assigned
$y = $x->z;  // no error

// or you could make your own class
class Whatever
{
    public $z;
}

$x = new Whatever();
$y = $x->z;  // it's there whether a value has been assigned or not

在这里https://3v4l.org/hOThV

查看
相关问题