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
$this->comment = array();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With