這是我的課程。 getPosts
方法返回一個數組,但我無法在proceedPosts
中獲得對它的訪問。當我試圖在瀏覽器中打印時,它向我顯示一個錯誤,$result
變量不是defined
。不明白爲什麼我不能通過另一個課程方法獲得結果
class myClass
{
public $myposts;
public function getPosts()
{
$result = $this->myposts = array('a','b','c');
return $result;
}
public function handlePosts()
{
echo $result;
}
}
$myObj = new myClass();
$myObj->getPosts();
$myObj-> handlePosts();
有人能解釋我爲什麼嗎?謝謝。
非常感謝你兄弟。它爲我工作。 –