从另一个php调用公共函数

时间:2014-12-12 14:06:41

标签: php wordpress

我正在使用WordPress插件,我有2个php文件。

class.php的代码为:

class Plugin_Name {

     public function say_hello() {
         echo "Hello";
     }

}

现在我想从另一个say_hello()文件中调用此welcome.php函数。

我试过

$hello_function = new Plugin_Name();
$hello_function->say_hello();

但它不起作用。有没有办法从另一个php调用公共函数?

1 个答案:

答案 0 :(得分:3)

您需要在另一个文件中包含第一个函数,这样另一个文件就知道代码在那里。在welcome.php的顶部添加

require_once('/path/to/class.php');
$hello_function = new Plugin_Name();
$hello_function->say_hello();
相关问题