0

I was wondering if it is possible to hide variables from the "include". In other words, I want certain classes/variables which are declared inside a PHP file to basically not be visible to any other PHP file which includes it. Is this possible? Is there maybe a way around it?

4
  • The point in including a file is that what is in it becomes available in the includer ... I don't think that what you are asking is possible Commented Aug 5, 2012 at 3:55
  • Well, yes, but if I do any kind of processing inside which uses variables, I don't want those variables/classes to be accessible outside. Commented Aug 5, 2012 at 3:58
  • if those variables are class parameters, you just need to put them private Commented Aug 5, 2012 at 3:58
  • Im not talking about class scope Commented Aug 5, 2012 at 3:59

3 Answers 3

2

Method 1: Separate those variable/class into yet another file, and call only the needed part of it. If you are going to use different part of the scripts in different context, place them in separate files and call them as you need it.

Method 2: After you include the file, unset the variables and destroy the classes.

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

1 Comment

I have come to this concussion a moment ago :) the second solution seems to work well! Thank you!
1

IMHO, I think it's about time you get an introduction to PHP5 OOP.
Take a look at Visibility afterwards.

1 Comment

I like how I constantly get people who think that half the people on this website have no idea how to program. The power of PHP is the ability to put functions/classes/variables into global scope making it very easy to setup a tool set inside your architecture. I would need to use OOP in ASP to achieve this. Thanks for the links.
0

Your include file could define a function that does all the work, and the variables can be local to that function. As long as you don't declare them global they'll be gone when the function returns.

This function name will be visible to the caller, but it's better than having everything visible.

Comments

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.