PHP Wordpress Functions.PHP获取类的实例(header.PHP中未定义变量)
functions.phpPHP Wordpress Functions.PHP获取类的实例(header.PHP中未定义变量),php,wordpress,oop,Php,Wordpress,Oop,functions.php final class Test { public function helloworld() { return "Hello World!"; } } $testy = new Test; 当我尝试调用$testy->helloworld()时;在header.php文件中,它确实给了我一个错误,比如变量未定义 当我在我的页眉php中调用实例$testy时,就像这样,然后将该实例与函数helloworld()一起使用,一切正
final class Test {
public function helloworld() {
return "Hello World!";
}
}
$testy = new Test;
当我尝试调用$testy->helloworld()时;在header.php文件中,它确实给了我一个错误,比如变量未定义
当我在我的页眉php中调用实例$testy时,就像这样
,然后将该实例与函数helloworld()一起使用,一切正常,但我需要在页脚中再次调用它,以使该实例也适用于我的页脚
因此,我想知道如何在functions.php中编写它,而不在header.php和footer.php中声明它
希望有人能帮我。你可以用
final class Test {
public function helloworld() {
return "Hello World!";
}
}
$testy = new Test;
$_GLOBAL['testy'] = $testy;
?>
还有其他方法吗?我如何使用$\u全局变量选择函数helloworld()?