|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2001-08-02 10:26 UTC] pmateesc at dynasty dot com
<?
$a = 1;
$b = 2;
function Sum() {
global $a, $b;
$b = &$a;
}
echo "a=$a b=$b";
?>
I expect echo to output "a=1 b=1" since within Sum I set the variable $b (which refers to global $b) as a reference to $a.
However, this works using $GLOBALS instead of the keyword global.
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Nov 05 19:00:01 2025 UTC |
Hi! What is posted in the manual does not work as expected: class DTO { public $msgs = "ergegefr"; public $a = 1; public $b = 2; function Insert(){ global $msgsb, $a, $b; $b = $a + $b; print $msgs; //Prints nothing print $b; //Prints 0 } }