Please look at the following two examples:
Example 1:
$variable = 'some value';
class Foo {
public function bar() {
global $variable;
print $variable;
}
}
Example 2:
$variable = 'some value';
class Foo {
public function bar() {
print $GLOBALS['variable'];
}
}
Examples can be used like this:
$foo = new Foo();
$foo->bar();
Both seem to do the same thing? What is the difference? Is one way better than the other? Why are there two different ways of doing this?
The first example seems strange to me because it looks like a declaration followed by using the variable without assigning it.. looks weird to me.
Thank you.