"access global variable from within a class" Answer’s


Why the surprise? That's a pretty logical variable scope problem there...

I suggest you use either the global keyword or the variable $GLOBALS to access your variable.

EDIT: So, in your case that will be:

global $a;



EDIT 2: And, since Vinko is right, I suggest you take a look at PHP's manual about variable scope.

Wednesday, March 31, 2021
answered 11 Months ago
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :