note 51132 deleted from language.references.whatdo by colder

From: Date: Sat, 24 Feb 2007 11:48:18 +0000
Subject: note 51132 deleted from language.references.whatdo by colder
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-123825@lists.php.net to get a copy of this message
Note Submitter: miqrogroove ---- More on references and globals: String variables are not automatically passed by reference in PHP. Some other languages, such as Visual Basic, will do that automatically for all variables. PHP will not. Consider the case where a function receives a global variable as a parameter and also has the same variable defined locally with the 'global' statement. Do the parameter and global variable now reference the same memory? No, they do not! Passing the global variable into the function as a parameter caused a second variable to be created by default. Here is an example of this scenario: <?php $teststring="Hello"; one(); function one(){ global $teststring; two($teststring); echo $teststring; // The value is "World" } function two($param){ global $teststring; $teststring="World"; echo $param; // The value is "Hello" $param="Clear?"; } ?> Enjoy

« previous php.notes (#123825) next »