我需要在 PHP 中初始化一个对象数组。 目前我有以下代码:
$comment = array();
当我向数组中添加一个元素时
public function addComment($c){
array_push($this->comment,$c);
}
这里,$c
是 Comment 类的一个对象。
但是当我尝试使用 $comment
访问该类的函数时,出现以下错误:
Fatal error: Call to a member function getCommentString() on a non-object
谁能告诉我如何在 php 中初始化对象数组?
谢谢 沙米
最佳答案
$this->comment = array();
关于php数组初始化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1805281/