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
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: 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

Add a Patch

Pull Requests

Add a Pull Request

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-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 25 23:01:29 2024 UTC