
Load function for native framework
Hello dear PHP Experts. Today I want to ask you for advice on how to be.
About the need to write my own “bicycle”, a framework, I would not want to go into it, it was simply necessary. Maybe I'm not doing everything right, correct if so, my extensions are loaded through the load ($ path) function in which you can then insert the definition of the absolute path or the ban on loading something, in general, the point is that it is not just require_once ( ) However, I ran into a big problem - variables ...
I encountered a problem when I started loading modules through it. The fact is that all the variables of the loaded module fall into the load () function and die safely in it without falling into global variables. That is, I cannot assign a variable in one module and use it in another. Now the question is how to get around this?
One way: add global $ html, $ ajax, $ user, $ tags, $ info to the load () function ... here I list all the variables that I need to “transfer” from module to module. We have to replenish the list of these variables in the course of work on the project - this is not convenient. Another way: global to declare one variable global $ _G; and to use only it for data transfer between modules is also not good, imposes certain restrictions in the project. Transfer all $ GLOBALS to a function via foreach () {global $ ($ var); } too wasteful ... but get_defined_vars () should be enumerated in theory before the module loads.
Please advise how to be?
About the need to write my own “bicycle”, a framework, I would not want to go into it, it was simply necessary. Maybe I'm not doing everything right, correct if so, my extensions are loaded through the load ($ path) function in which you can then insert the definition of the absolute path or the ban on loading something, in general, the point is that it is not just require_once ( ) However, I ran into a big problem - variables ...
function load($path) {
static $debug;
if (file_exists($path)) {
$debug[] = "load($path): Success";
require_once( $path );
return true;
}
else {
$debug[] = "load($path): Path not exists";
return false;
}
}
I encountered a problem when I started loading modules through it. The fact is that all the variables of the loaded module fall into the load () function and die safely in it without falling into global variables. That is, I cannot assign a variable in one module and use it in another. Now the question is how to get around this?
Please advise how to be?