Click to See Complete Forum and Search --> : [RESOLVED] Accesing global var from inside a method


Ipsens
January 4th, 2008, 04:14 PM
$code = 5555;

class A
{
public function foor()
{
echo $GLOBAL['code'];
}
}



$a = new A;
$a->foor();

I've expected it to echo 5555...
But it doesn't.

How do I make it to do so,
That is..., object's method should see global variable $code

PeejAvery
January 4th, 2008, 06:37 PM
You are close. To reference a globl variable in a class you want...

$code = 5555;

class A
{
public function foor()
{
global $code;
echo $code;
}
}



$a = new A;
$a->foor();

Ipsens
January 4th, 2008, 07:43 PM
Thanks PeejAvery,

It works now!
;)