[英]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.