|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[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 PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Nov 02 12:00:01 2025 UTC |
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?