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();
}
}
But we not get content from function test()
.
Tell me please where error ?
Your issues:
class
named function
. function
is a keyword
. $Func
, but make call using $Function
If you remove these two issues, your code will work correctly:
class ClassController{
public function test(){
echo 'this is test';
}
}
class ClassFunction{
public function testfuncton1(){
ClassController::test();
}
}
$Func = new ClassFunction();
$Func->testfuncton1();
This should print this is a test
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.