I create instances of the same class with inside a for loop. But it seems that these instances refer the same object somehow.
Here is the code;
class Content{
/**
* current content id
* @var int
*/
public $id;
function __construct($id){
echo " <br>Construct content ".$id;
}
function createContentOfPage($id){
$contentIdArray = $this->dbo->getContentIdsForPage($id);
/*var_dump of $contentIdArray aray is given below*/
if(is_array($contentIdArray) && count($contentIdArray)>0){
$contentArray = array();
foreach ($contentIdArray as $Id){
echo "<br>Content id: ".$Id['content_id'];
array_push($contentArray, new Content(($id['content_id'])));
}
}
}
}
Here is the var_dump of $contentIdArray
array(2) {
[0]=>
array(1) {
["content_id"]=>
string(1) "1"
}
[1]=>
array(1) {
["content_id"]=>
string(1) "2"
}
}
If I run the createContentOfPage() here is the out put;
Content id: 1
Construct content 1
Content id: 2
Construct content 1
What is that I'm doing wrong in here? Please help.
$Id,$id, and a member variable$idat the same time.