【发布时间】:2011-12-10 08:43:38
【问题描述】:
我最近意识到,如果使用更好/更具描述性的对象,我目前的项目方法会大大改进。因此,我意识到我希望一个对象数组成为另一个类的成员。
编辑:我不清楚我的问题是什么。因此,我的问题是:如何在 LogFile 类中有一个包含 Match 类型对象的数组?
class LogFile
{
public $formattedMatches;
public $pathToLog;
public $matchCount;
** An array called matches that is an array of objects of type Match **
}
class Match
{
public $owner;
public $fileLocation;
public $matchType;
}
最终我希望能够做类似的事情:
$logFile = new LogFile();
$match = new Match();
$logFile->matches[$i]->owner = “Brian”;
我该如何做我所描述的?换句话说,我需要在类LogFile 中做什么来创建一个包含Match 类型对象的数组?
【问题讨论】:
-
我该怎么做?换句话说,我需要在类 LogFile 中做什么来创建一个包含 Match 类型的对象的数组?
-
我不想评论所有个人的答案,我只想对大家的帮助表示感谢。我看现在怎么样了。缺乏强大的格式规则让我仍然感到厌烦。