douji9816 2015-10-03 16:08
浏览 26
已采纳

从空值php 5,5创建默认对象

I try to create new stdClass but still nothing and this code make an error: Warning: Creating default object from empty value.

function __construct($params) {
    parent::__construct($params);
    //$this -> view -> controller = null;
    $this -> view -> controller = new stdClass(); // <-- HERE IS ERROR 
    $this -> view -> controller = 'Index';

    require_once 'models/_index_model.php';
    $this -> model = new Index_model();

    $action = 'News';
    if(isset($params[1])){ $action = ucfirst($params[1]); }

    $this->date = 'Today';
    if(isset($params[2])) $this->date = ucfirst($params[2]);

    $this->$action($this->date);
}
  • 写回答

1条回答 默认 最新

  • doupao6698 2015-10-03 16:28
    关注

    The problem is, that there's no value for the variable $view

    I'm not sure what you'd like to achieve, but the code should work if you implement it like in the following example:

    function __construct($params) {
        parent::__construct($params);
    
        $this -> view = new stdClass(); // create a new stdClass object
        $this -> view -> controller = 'Index'; // assign the controller value
    
        // ... and so on
    }
    

    So the main problem here, is that the variable $view was not declared, or its value is not an object.

    Feel free to ask in the comment section if there are more questions

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100