以下是我班级的代码:
<?php
include ('Special.php');
class SpecialContainer
{
private $dataArray;
public function _construct()
{
$this->dataArray = array();
echo"Created new Location instance<br/>";
}
public function addSpecialItem($Special_Item)
{
array_push($this->dataArray, $Special_Item);
}
}
?>
它在另一个php文件中的以下行引发错误:
$SpecialContainerObj->addSpecialItem($SpecialObj);
错误是这样的:
Warning: array_push() [function.array-push]: First argument should be an array in /home/**********s/SpecialContainer.php on line 16
...
我很困惑,有人可以澄清我如何解决这个问题。感谢
答案 0 :(得分:3)
public function _construct()
缺少下划线。您还应注意,您的邮件永远不会echo
d
public function __construct()
但是,您应该在类声明
中直接定义类似的内容class Foo {
private $dataArray = array();
// Other code
}