假设您有一个独特的对象,它被所有其他类和函数使用...像
在您的函数中如何访问此对象?
$application
这样。在您的函数中如何访问此对象?
using a global variable in each of you functions:
global $application; $application->doStuff();
creating a function, like
application()
that instantiates the object into a static variable and returns it; then use this function everywhere you need to access the object:application()->doStuff();
create a singleton thing, like a static method inside the object class which returns the only instance, and use this method to access the object:
Application::getInstance()->doStuff();
KingCrunch & skwee: Pass the application object as argument to each function/class where is needed
... public function __construct(Application $app, ...){ ....