for 루프에서 동일한 클래스의 인스턴스를 만듭니다. 그러나이 인스턴스들은 어떻게 든 동일한 객체를 참조하는 것으로 보입니다.두 개의 PHP 객체가 동일한 인스턴스를 참조합니다.
다음은 코드입니다. 여기
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'])));
}
}
}
}
은 $ contentIdArray의 위해서 var_dump입니다
array(2) {
[0]=>
array(1) {
["content_id"]=>
string(1) "1"
}
[1]=>
array(1) {
["content_id"]=>
string(1) "2"
}
}
내가 여기 createContentOfPage()
가 넣어 밖으로 실행하는 경우;
Content id: 1
Construct content 1
Content id: 2
Construct content 1
내가 여기서 잘못하고있는 것은 무엇입니까? 도와주세요.
'$ Id','$ id', 그리고 멤버 변수'$ id'를 동시에 사용하여 혼란스럽게 할 것입니다. –