为什么在构造函数PHP中初始化后数组未满?
我有两类PHP: 轮廓 公共档案 在Publicprofile类中,有:为什么在构造函数PHP中初始化后数组未满?,php,oop,Php,Oop,我有两类PHP: 轮廓 公共档案 在Publicprofile类中,有: public function index($id){ $profile = new profile($id, true); $profile->index(); } 因此,这里我创建了一个新的对象配置文件 让我们来看看课程简介: 函数getTemplate;-形成一个数组$this->data 如果要在执行getTemplate后立即显示此数组,将通过var_dump查看,该数组包
public function index($id){
$profile = new profile($id, true);
$profile->index();
}
因此,这里我创建了一个新的对象配置文件
让我们来看看课程简介:
函数getTemplate;-形成一个数组$this->data
如果要在执行getTemplate后立即显示此数组,将通过var_dump查看,该数组包含带键的数据:
内部视图
看法
调用方法$profile->index时-此数组不同:
类配置文件中的方法索引:
我的代码有什么错,一个类中的源数组在两个方法中是不同的
函数GetTemplate:
您的第一个索引函数发生冲突,它将导致无限循环,您正在调用没有参数的函数,因此您将收到一个错误&timeout您可以共享getTemplate的内容吗?当var_dump仍然包含值时,您尝试在何处进行var_dump?如果使var_dump$this->data在方法getTemplate的末尾,我会看到数组项:view_inside,view,我编辑了问题并添加了函数getTemplate@Alice实际上,索引没有理由单独调用构造函数。我试图重新创建一个类似的代码体系结构,它运行良好。你看到你的代码有什么不同吗:你是否尝试删除父::\u构造;“有可能吗?”爱丽丝,我也不明白。也许你可以尝试使用或任何其他代码共享网站重现这种奇怪的行为,这样我们就可以看到哪里出了问题,为什么出了问题?
class Profile extends Auth {
public $data = array();
public function __construct($idUser = null, $view = false){
parent::__construct();
$this->getTemplate();
}
}
}
public function index(){
var_dump($this->data); die(); // Here there are not keys view_inside, view
$this->route();
}
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
}