类中嵌套类,又嵌套数组和类,整糊涂了,求解

WBOY
Release: 2016-06-13 12:34:29
Original
802 people have browsed it

类中嵌套类,再嵌套数组和类,整糊涂了,求解

本帖最后由 jerryleeee 于 2013-10-25 03:26:59 编辑
<br />
class Editor<br />
{<br />
	var $Error = '' ;<br />
	var $Pages;<br />
	function vol()<br />
	{<br />
		$Pages = array();<br />
		$this->Pages[] = new page;<br />
	}<br />
}<br />
<br />
class Page<br />
{<br />
	var $Id = '';<br />
	var $BackImage;<br />
	function vol()<br />
	{<br />
		$BackImage = array();<br />
		$this->$BackImage[] = new Decorator;<br />
	}<br />
}<br />
<br />
class Decorator<br />
{<br />
	var $Ext = '';<br />
}<br />
<br />
_________________________________________________________<br />
<br />
//我在使用这个类的时候<br />
$Editor = new Editor;<br />
$Editor->vol();<br />
$Editor->Pages[0]->vol();  //对象定义完成?我只初始化了Pages[0]下的class Decorator对象,<br />
为什么下面我可以直接使用page[2]和所有page数组其他元素中的class Decorator ,<br />
而不需要我$Editor->Pages[2]->vol()呢?<br />
<br />
<br />
$Editor->Pages[0]->BackImage[0]->Ext = 'str' ;<br />
$Editor->Pages[2]->BackImage[2]->Ext = 'str2' ;<br />
$Editor->Pages[5]->BackImage[4]->Ext = 'str6' ; //这样使用没有报错<br />
<br />
Copy after login

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!