php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #12533 Reference and global keyword don't work as documented
Submitted: 2001-08-02 10:26 UTC Modified: 2001-12-14 14:37 UTC
From: pmateesc at dynasty dot com Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 4.0.6 OS: W2k, Linux
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: pmateesc at dynasty dot com
New email:
PHP Version: OS:

 

 [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.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2001-12-14 14:37 UTC] yohgaki@php.net
This is explained in the Manual. Please ask support question to php-general.   
Note: Reference is not a pointer. This is confiuing, but it will not be fixed.
 [2010-11-09 23:13 UTC] magister99 at hotmail dot com
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
   }
}
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri May 03 20:01:31 2024 UTC