的index.php
include('./class1.php');
include('./class2.php');
$Func = new function();
$Func->testfuncton1();
Run Code Online (Sandbox Code Playgroud)
class1.php
class controller{
public function test(){
echo 'this is test';
}
}
Run Code Online (Sandbox Code Playgroud)
class2.php
class function{
public function testfuncton1(){
controller::test();
}
}
Run Code Online (Sandbox Code Playgroud)
但是我们没有从功能中获得内容test().
请告诉我哪里有错误?
你的问题:
class名字function.function是一个keyword.$Func,但使用$Function如果您删除这两个问题,您的代码将正常工作:
class ClassController{
public function test(){
echo 'this is test';
}
}
class ClassFunction{
public function testfuncton1(){
ClassController::test();
}
}
$Func = new ClassFunction();
$Func->testfuncton1();
Run Code Online (Sandbox Code Playgroud)
这应该打印 this is a test