gpt4 book ai didi

php数组初始化

转载 作者:可可西里 更新时间:2023-11-01 00:53:38 25 4
gpt4 key购买 nike

我需要在 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com