Global PHP class in functions?
问题 Is there a way to access one instance of a class inside functions in PHP? Like this: include("class.php"); $bla=new Classname(); function aaa(){ $bla->DoSomething(); //Doesn't work. } $bla->DoSomething(); //Works. 回答1: If I interpret your question correctly, then the proper way to do this is create a singleton class. class Singleton { private static $instance; private function __construct() {} private function __clone() {} public static function getInstance() { if (!Singleton::$instance