note 51132 added to language.references.whatdo

From: Date: Mon, 21 Mar 2005 09:40:32 +0000
Subject: note 51132 added to language.references.whatdo
Groups: php.notes 
Request: Send a blank email to php-notes+get-86736@lists.php.net to get a copy of this message
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 ---- Manual Page -- http://www.php.net/manual/en/language.references.whatdo.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+51132 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+51132&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+51132&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+51132&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+51132&report=yes&reason=useless Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+51132&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+51132&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#86736) next »