optikalefx Posted August 30, 2010 Share Posted August 30, 2010 My php needs a wrapper function for require. Because there is a specific naming scheme thats always applied, and i want to log every require. so i made $this->_require($file) The problem is, the scope isn't carried over, so any variables that exists in the method that called _require don't exist in the required file. But they DO exist when i don't use the wrapper function. So it seems in order for the variable scope to carry into the required file the require itself has to be in the same function call. Is there any solution to me being able to make a wrapper method for require? thanks! Link to comment https://forums.phpfreaks.com/topic/212079-create-a-wrapper-method-for-require/ Share on other sites More sharing options...
wildteen88 Posted August 30, 2010 Share Posted August 30, 2010 Not sure what you're doing but as you're using objects then maybe looking at the autoload function may help you. If its not what you're after then you'll want to post your current code here. Link to comment https://forums.phpfreaks.com/topic/212079-create-a-wrapper-method-for-require/#findComment-1105242 Share on other sites More sharing options...
AbraCadaver Posted August 30, 2010 Share Posted August 30, 2010 This really isn't a good idea. Variables included/required in a function are going to be local to that function. I can show two options but recommend that you not use a wrapper. You can modify the required files to define vars something like this (then they are available globally): $GLOABLS['myvar'] = 'something'; Or you can modify the function and the _require call: function _require($file) { require($file); return get_defined_vars(); } extract($this->_require('/path/to/some/file.php')); Link to comment https://forums.phpfreaks.com/topic/212079-create-a-wrapper-method-for-require/#findComment-1105247 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.