At 11:52 AM +0300 5/28/04, Ciprian Trofin wrote:
Hi All,

My system: Windows NT 5.0 build 2195 / Apache/1.3.23 - PHP 4.1.1

Here is a nice snippet:
___________________________________________________________________________
<?
function test() {
 $GLOBALS['test'] = 1;
 $test = 2; }

test();
echo $test;
?>
__________________________________________________________________________

the result: 1 (however, I expected to see "2")




If I change to: <? function test() { global $test; $GLOBALS['test'] = 1; $test = 2; }

test();
echo $test;
?>
___________________________________________________________________________

the result: 2

I understand the concept o local and global variables, but isn't $GLOBALS
supposed to work as an alternative to "global" statement ?


Not exactly. It allows to you access variables in the global context, but it doesn't make the variable itself global; only the 'global' declaration does that.

        steve


-- +--------------- my people are the people of the dessert, ---------------+ | Steve Edberg [EMAIL PROTECTED] | | University of California, Davis (530)754-9127 | | Programming/Database/SysAdmin http://pgfsun.ucdavis.edu/ | +---------------- said t e lawrence, picking up his fork ----------------+

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Reply via email to