0

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
  • 2
    Could you show us the code you are using? Commented 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/… Commented 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. Commented Aug 6, 2012 at 17:00

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

2 Comments

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.
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.