php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #52281 New Unref function - breaks reference between variables.
Submitted: 2010-07-07 19:02 UTC Modified: 2010-12-01 15:34 UTC
From: keithm at aoeex dot com Assigned:
Status: Wont fix Package: Scripting Engine problem
PHP Version: Irrelevant OS:
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: keithm at aoeex dot com
New email:
PHP Version: OS:

 

 [2010-07-07 19:02 UTC] keithm at aoeex dot com
Description:
------------
An addition to PHP that would be nice is a way to break a reference between two variables, without destroying them.  Currently, the only way I found to break a reference is to use unset($var), however this causes the variable to be destroyed which causes can cause undesirable side-effects on classes.

Suggested function: unref($var) - Removes references from $var.  The function would give $var whatever value it currently has via it's reference, and then removes the reference.



Test script:
---------------
Example of problem prompting this:
See: http://www.aoeex.com/extras/unref.php
Pastebin (in-case main url is down): http://pastebin.com/BtWeasC1



Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-07-30 07:37 UTC] bastard dot internets at gmail dot com
keithm at aoeex dot com - Basically, you mean a shortcut for referencing: "$temp_b = $b; $b =& $temp_b; unset($temp_b);"?  In other words...

<?php

$a = 1;
$b =& $a; // reference made

$temp_b = $b; $b =& $temp_b; unset($temp_b);  // break reference to $a, but could be shortened to a new built-in function "unref($b);"

$b = 2;

echo $a."\n"; // 1
echo $b."\n"; // 2

?>

The only user defined function I could get to work even similarly is...

<?php

function &unref($var) {
	return $var;
	}

$b =& unref($a);

?>

With these shortcuts in mind, is a new built-in function still needed?
 [2010-12-01 15:34 UTC] jani@php.net
-Status: Open +Status: Wont fix -Package: Unknown/Other Function +Package: Scripting Engine problem
 [2010-12-01 15:34 UTC] jani@php.net
Nope, see above.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Thu Jul 03 08:01:34 2025 UTC