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 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?
3
-
2Could you show us the code you are using?Edoardo Pirovano– Edoardo Pirovano2011-07-21 15:18:42 +00:00Commented Jul 21, 2011 at 15:18
-
I'm not sure if it relates, but there may be something fishy with include(s) in some instances with Codeigniter. I found your question while searching for an answer to my own: stackoverflow.com/questions/8156743/…Slobaum– Slobaum2011-11-16 19:30:06 +00:00Commented Nov 16, 2011 at 19:30
-
I'm sorry that I abandoned this question. I was new to StackOverflow at the time of asking. I'm not facing this problem anymore but unfortunately have no idea how I resolved it because it was so long ago.michael– michael2012-08-06 17:00:05 +00:00Commented Aug 6, 2012 at 17:00
Add a comment
|
1 Answer
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
2 Comments
michael
Sorry for not making it clear, but the i'm using the include inside the same function which I'm attempting to use the included content. When I say caller and callee I mean the function that actually calls the include() function.
Damien Pirsy
Well, in this case you better provide some code or it would be nearly impossible to spot out errors! Please edit your question adding the function you mention, thanks.