newbie - global variable
Posted: Fri Aug 20, 2010 6:56 pm
Hello EveryOne!
could someone please tell what I am doing wrong (if I am doing anything wrong at all)
I am confused with the global variables in PHP.
the following code works just fine
function testGlobal()
{
global $globvar;
$globvar=3;
echo " \$globvar: $globvar";
}
testGlobal();
and prints out the value of globvar on the page of browser.
however, if I assign the value to this variable on the same line I declare it - I am getting blank page in the browser.
function testGlobal()
{
global $globvar=3;
echo " \$globvar: $globvar";
}
testGlobal();
Am I doing something wrong? is it bug in PHP? is something wrong with my settings?
just in case, my settings/versions are:
uname -srvmo
Linux 2.6.18-194.11.1.el5 #1 SMP Tue Aug 10 19:05:06 EDT 2010 x86_64 GNU/Linux
PHP 5.3.3 (cli) (built: Aug 18 2010 12:08:14)
Copyright (c) 1997-2010 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies
thank you in advance!
could someone please tell what I am doing wrong (if I am doing anything wrong at all)
I am confused with the global variables in PHP.
the following code works just fine
function testGlobal()
{
global $globvar;
$globvar=3;
echo " \$globvar: $globvar";
}
testGlobal();
and prints out the value of globvar on the page of browser.
however, if I assign the value to this variable on the same line I declare it - I am getting blank page in the browser.
function testGlobal()
{
global $globvar=3;
echo " \$globvar: $globvar";
}
testGlobal();
Am I doing something wrong? is it bug in PHP? is something wrong with my settings?
just in case, my settings/versions are:
uname -srvmo
Linux 2.6.18-194.11.1.el5 #1 SMP Tue Aug 10 19:05:06 EDT 2010 x86_64 GNU/Linux
PHP 5.3.3 (cli) (built: Aug 18 2010 12:08:14)
Copyright (c) 1997-2010 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies
thank you in advance!