[英]PHP How to call a function from another class and another file?
index.php
include('./class1.php');
include('./class2.php');
$Func = new function();
$Func->testfuncton1();
class1.php
class controller{
public function test(){
echo 'this is test';
}
}
class2.php
class function{
public function testfuncton1(){
controller::test();
}
}
但是我们不能从功能test()
获得内容。
告诉我哪里出错了?
您的问题:
function
的class
。 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();
这应该打印this is a test
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.