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?
-
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 possibleOussama Jilal– Oussama Jilal2012-08-05 03:55:56 +00:00Commented 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.Serguei Fedorov– Serguei Fedorov2012-08-05 03:58:05 +00:00Commented Aug 5, 2012 at 3:58
-
if those variables are class parameters, you just need to put them privateOussama Jilal– Oussama Jilal2012-08-05 03:58:52 +00:00Commented Aug 5, 2012 at 3:58
-
Im not talking about class scopeSerguei Fedorov– Serguei Fedorov2012-08-05 03:59:25 +00:00Commented Aug 5, 2012 at 3:59
3 Answers
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.
1 Comment
IMHO, I think it's about time you get an introduction to PHP5 OOP.
Take a look at Visibility afterwards.
1 Comment
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.