我有以下 PHP 代码:
class SQLStatements {
public function __construct($iName) {
$this->name = $iName;
$this->sqlStatement = array ();
}
public function addStatement($iSQLStatement) {
$this->sqlStatement [] = $iSQLStatement;
}
...other functions...
}
print_r ($ss);
$sqlStatements->addStatement ( $ss );
print_r ($sqlStatements);
输出是:
SQL语句对象 ( [id] => 300 [时间戳] => 201301090222 [夹具] => 主场 v 客场 [结果] => 主页 [fixtureDateTime] => 2013-01-11 [bookmakerOdds] => 数组 ( [0] => 2.15 [1] => 2.22 [2] => 2.05 [3] => 2.05 [4] => 2.15 [5] => 2.20 [6] => 2.14 ) ) SQLStatements 对象 ( [名称] => 声明 [sqlStatement] => 数组 ( [0] => SQLStatement 对象 ( [id] => 300 [时间戳] => 201301090222 [夹具] => 主场 v 客场 [结果] => 主页 [fixtureDateTime] => 2013-01-11 [bookmakerOdds] => 数组 ( [0] => 2.15 [1] => 2.22 [2] => 2.05 [3] => 2.05 [4] => 2.15 [5] => 2.20 [6] => 2.14 ) ) ) ) SQL语句对象 ( [id] => 300 [时间戳] => 201301090222 [夹具] => 主场 v 客场 [结果] => 主场 v 客场 - 平局 [fixtureDateTime] => 2013-01-11 [bookmakerOdds] => 数组 ( [0] => 3.50 [1] => 3.50 [2] => 3.40 [3] => 3.40 [4] => 3.30 [5] => 3.50 [6] => 3.28 ) ) SQLStatements 对象 ( [名称] => 声明 [sqlStatement] => 数组 ( [0] => SQLStatement 对象 ( [id] => 300 [时间戳] => 201301090222 [夹具] => 主场 v 客场 [结果] => 主场 v 客场 - 平局 [fixtureDateTime] => 2013-01-11 [bookmakerOdds] => 数组 ( [0] => 3.50 [1] => 3.50 [2] => 3.40 [3] => 3.40 [4] => 3.30 [5] => 3.50 [6] => 3.28 ) ) [1] => SQLStatement 对象 ( [id] => 300 [时间戳] => 201301090222 [夹具] => 主场 v 客场 [结果] => 主场 v 客场 - 平局 [fixtureDateTime] => 2013-01-11 [bookmakerOdds] => 数组 ( [0] => 3.50 [1] => 3.50 [2] => 3.40 [3] => 3.40 [4] => 3.30 [5] => 3.50 [6] => 3.28 ) ) ) )
$ss
是一个SQLStatement
对象,并且该SQLStatements
对象是对象的集合SQLStatement
。但是,从输出中可以看出,SQLStatements->SQLStatement[0] 和 SQLStatements->SQLStatement[1] 是相同的。我期待 SQLStatements->SQLStatement[0]->结果是 'Home',而不是 'Home v Away - Draw'。我究竟做错了什么?