dongshang3309 2014-09-24 12:30
浏览 23

为什么在构造函数PHP初始化后数组未满?

I have a two classes PHP:

  1. Profile
  2. Publicprofile

At Publicprofile class there are:

public function index($id){
        $profile = new profile($id, true);
        $profile->index();
}

So, here I create a new object profile.

Let's some to see class Profile:

class Profile extends Auth {

    public  $data = array();
        public function __construct($idUser = null, $view = false){
            parent::__construct();
            $this->getTemplate();
        }
    }
}

The function getTemplate(); - forms an array $this->data

If to show at once this array after execute getTemplate(), will see (via var_dump), that array contains data with a keys:

  1. view_inside
  2. view

When is called a method $profile->index() - this array not is same:

Method index in class Profile:

public function index(){
        var_dump($this->data); die(); // Here there are not keys view_inside, view
        $this->route();
    }

What is wrong at my code, that the source array in one class is different at two methods?

Function GetTemplate():

public function getTemplate(){

                $this->data['view_inside']   = 'profile/doctor/index';
                $this->data['view_left']     = 'profile/doctor/left';
                $this->data['view_edit']     = 'profile/doctor/personal_update'; 
                $this->data['view_personal'] = 'users/doctor/personal';
var_dump($this->data); // All right
}
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 python:excel数据写入多个对应word文档
    • ¥60 全一数分解素因子和素数循环节位数
    • ¥15 ffmpeg如何安装到虚拟环境
    • ¥188 寻找能做王者评分提取的
    • ¥15 matlab用simulink求解一个二阶微分方程,要求截图
    • ¥30 乘子法解约束最优化问题的matlab代码文件,最好有matlab代码文件
    • ¥15 写论文,需要数据支撑
    • ¥15 identifier of an instance of 类 was altered from xx to xx错误
    • ¥100 反编译微信小游戏求指导
    • ¥15 docker模式webrtc-streamer 无法播放公网rtsp