Php global variable get lost
I must use a global variable (reference of an object). Depending on some circumstances, I must load different scripts to use. All scripts must use this $mailer. Sadly, to make this decision, I use a static function which "forgets" then the global variables.
$mailer = new Mailer();
myFrameWork::loadModule();
....
public static function callModule()
{
include_other_module_depends_on_circumsta开发者_开发问答nces_etc
}
but the included scripts doesn't know $mailer variable. Its OK, since its a method. But I dont want to pass this variable to callModule, I want a general solution. If I just used:
$mailer = new Mailer();
include_other_module_depends_on_circumstances_etc
then it works alright.
I’d higly suggest not to use static methods for this kind of work; with OOP it is pretty easy to use normal objects to do initializing and stuff.
Given your class myFrameWork is fully static class, why not pass that object to it with another static class and store it in private static variable? That way you don’t need to pollute the function call and still can use the value where needed.
精彩评论