php4: problems with variable access in a class method
I have created a class that works as a singleton (though that's not related to the problem). I have noticed that the constructor of the class doesn't get to access the value of a variable that has already been defined in a prevoius include.
It's something like this: A.php includes B.php (B is the one that defines the variable). A.php includes singleton.php then in A.php I try to get an instance of singleton. Teting, I was able to see that the variable value is reachable outside of the class definition (by testing with echos). But inside the class (in the constructor, to be precise), that variable is empty. What can I do? :scratch: |
I think that you need to give us a little more to go on. I suspect that it is a problem with the code, so can you post the relevant portions of the code.
|
Say... it's something like this:
variable.php Code:
<? Code:
<? Code:
<? Code:
The outside value of $VARIABLE is something What do you think? |
not sure if this will work but try this:
include_once "variable.php"; include_once "singleton.php"; $instance = new Singleton() $instance -> getInstance(); |
I'll try tomorrow at the office... but I think it will fail, as it is a static method.
|
From the manual on function scope:
Quote:
If you wish to access $VARIABLE as a global variable then you will need to use the keyword global Code:
function Singleton() { |
All times are GMT -5. The time now is 03:04 AM. |