php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #8115 variable passed by reference incorrectly handled
Submitted: 2000-12-05 06:27 UTC Modified: 2000-12-05 06:33 UTC
From: christian at architech dot no Assigned:
Status: Closed Package: Scripting Engine problem
PHP Version: 4.0.2 OS: linux
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: christian at architech dot no
New email:
PHP Version: OS:

 

 [2000-12-05 06:27 UTC] christian at architech dot no
It concerns variables passed by reference... and the unset() function.

# Let's define a very simple function that converts an array to a string :
function foo(&$a)
{
   $an_array = array("abcdef");
   unset($a);
   
   for ($i=0; $i<sizeof($an_array); $i++)
	$a = $a . $an_array[$i];
}

# and call it :
foo($my_var);

# $my_var is NOT EQUAL TO "abcdef" !!!!!

However it works fine when we don't try to unset the $a variable. (replacing the line with $a = "").

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2000-12-05 06:33 UTC] stas@php.net
This is exactly as it is meant to work. Please read
"References explained" in the manual. When you do the unset,
you effectively destroy local variable $a, breaking the
reference. Now when you mention $a again, it's not
referenced to $my_var anymore - it's a new variable.
 
PHP Copyright © 2001-2026 The PHP Group
All rights reserved.
Last updated: Sun Jun 28 16:00:01 2026 UTC