Req #52281 [Com]: New Unref function - breaks reference between variables.

From: Date: Fri, 30 Jul 2010 05:37:25 +0000
Subject: Req #52281 [Com]: New Unref function - breaks reference between variables.
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-152958@lists.php.net to get a copy of this message
Edit report at http://bugs.php.net/bug.php?id=52281&edit=1 ID: 52281 Comment by: bastard dot internets at gmail dot com Reported by: keithm at aoeex dot com Summary: New Unref function - breaks reference between variables. Status: Open Type: Feature/Change Request Package: Unknown/Other Function PHP Version: Irrelevant Block user comment: N New Comment: 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? Previous Comments: ------------------------------------------------------------------------ [2010-07-07 19:02:46] 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 ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/bug.php?id=52281&edit=1

« previous php.bugs (#152958) next »