php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #31688 Assignment by reference to a static variable doesn't work properly
Submitted: 2005-01-25 15:04 UTC Modified: 2005-01-25 15:22 UTC
From: mike at somosis dot co dot uk Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 4.3.10 OS: FreeBSD (experienced on others)
Private report: No CVE-ID: None
 [2005-01-25 15:04 UTC] mike at somosis dot co dot uk
Description:
------------
Static variables that are assigned to by reference in a function lose the assignment when the function terminates.

Reproduce code:
---------------
function a(&$v, $s) {
	static $x;

	if($s)
		$x =& $v;
	
	print("\$x in a: {$x}<br />\n");
}

$c = 1;

a($c, true);
a($c, false);


Expected result:
----------------
$x in a: 1
$x in a: 1


Actual result:
--------------
$x in a: 1
$x in a: 


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-01-25 15:22 UTC] sniper@php.net
RTFM:

http://www.php.net/variables.scope
"..assigning a reference to a static variable, it's not remembered.."

Last example in the page.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Sep 18 21:01:26 2024 UTC