类中嵌套类,再嵌套数组和类,整糊涂了,求解
本帖最后由 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 />
Copier après la connexion
Déclaration de ce site Web
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn
Derniers articles par auteur
-
2024-10-22 09:46:29
-
2024-10-13 13:53:41
-
2024-10-12 12:15:51
-
2024-10-11 22:47:31
-
2024-10-11 19:36:51
-
2024-10-11 15:50:41
-
2024-10-11 15:07:41
-
2024-10-11 14:21:21
-
2024-10-11 12:59:11
-
2024-10-11 12:17:31