객체를 사용하여 마지막으로 작업 한 지 오래되었습니다. 나는 내가 잘못한 것을 알아낼 수 없다. 다른 클래스를 속성으로 포함하는 클래스가 있습니다. Item()에서 ItemDetail()을 인스턴스화 한 후 설명 값을 가져올 수 없습니다. var_dump ($ item) $ detail의 값에 대해 NULL을 준다. 도와주세요. 고맙습니다.다른 객체에서 객체 값을 가져 오는 방법
<?php
class Item
{
private $name;
private $detail;
function __construct() {
$this->name = 'some name';
$this->detail = new ItemDetail();
}
function getDetail() {
return $this->detail;
}
}
class ItemDetail
{
private $description;
function __construct() {
$this->description = 'some description';
}
function getDescription {
return $this->description;
}
}
$item = new Item();
echo $item->getDetail()->getDescription();
//var_dump($item);
?>
에 관하여, 어떤 방법도없이? – samayo