可能重複:
Call function of class ONE from class TWO without extend?訪問功能使用類對象的
爲什麼不起作用?
class A {
function one() {
echo "Class A";
}
}
class B {
function two() {
echo "Class B";
$a->one();
}
}
$a = new A;
$b = new B;
$b->two();
標題應該是:「它爲什麼要工作?」 - 也許錯誤報告有幫助,你應該得到一個致命的錯誤。 – hakre
查找[變量範圍](http://php.net/manual/en/language.variables.scope.php) – Phil