可能重复:
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