Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

php Array Initialization

I need to initialize an array of objects in PHP. Presently I have the following code:

$comment = array();

And when i am adding an element to the array

public function addComment($c){
    array_push($this->comment,$c);
}

Here, $c is an object of class Comment.

But when I try to access an functions of that class using $comment, I get the following error:

Fatal error: Call to a member function getCommentString() on a non-object

Can anyone tell me how to initialize an array of objects in php?

Thanks Sharmi

like image 263
Sharmi Avatar asked Dec 05 '25 18:12

Sharmi


1 Answers

$this->comment = array();
like image 121
philfreo Avatar answered Dec 08 '25 08:12

philfreo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!