php - Creating variables using $GLOBALS -
I am currently working on a php framework, in some cases, such as ZendFramework.
My "problem" I have a variable number of classes (model, controller), e.g. Http_handler Now I have many such classes, which I can not set all of these manuals in variables.
Can I use $ globals for $ variableVar?
foreach ($ classes as $ square) {include_once ($ square. '.php'); $ Global [$ square] = new $ square; }
Is this a new variable that will be accessible through the entire code? Example:
// ... Code $ http_handler-> Send request ($ someArgs); // ... code
this will happen, but you have to import the global variable In the field of method:
function fu () {global $ http_handler;
Although there are better solutions for this. See for example
I used a singleton pattern to ask a question about how to organize all these classes recently, maybe some answers give you additional thought:
Comments
Post a Comment