PHP Coding tips & tricks. Function & error explanation, coding style, how tos etc. Short notes posted directly from developer work environment.
PHP Coding Tips
Tuesday, August 7, 2012
How to access global variable in php ?
If you are in a function on class method scope, you can gain access to a global variable by using a global keyword.$x = 5;
function myFunc() {
global $x;
echo $x;
}Remeber that using globals usually isn't a good idea. Better idea would be divide your globals by categories/modules and store it in static variables of some classes.
No comments:
Post a Comment