I'mu using the Codeigniter framework and I have an include_once('filename'); at the beginning of a function. In stepping through the code in debug mode the caller function evaluates the filename properly. I can then actually steps through the file line by line I'm attempting to include. The variables show up as I'm in the included file properly, and as soon as I exit out of the include file and back to the caller function that has the开发者_如何学JAVA include_once() call, all the data is gone and the variables that were set in 'filename' are uninitialized. What could possibly be causing this type of behavior?
Maybe (i.e., surely) the problem is that, as you said, you're including the file INSIDE A FUNCTION. So, all variables will exist only inside the scope of that function, and not outside of it.
You could either declare those variables global (which is frowned upon), or better have the function return the values you need from the variables of your included file.
Learn more on PHP Variable scopes
精彩评论