note 62727 added to function.extract

From: Date: Wed, 08 Mar 2006 12:21:59 +0000
Subject: note 62727 added to function.extract
Groups: php.notes 
Request: Send a blank email to php-notes+get-105042@lists.php.net to get a copy of this message
And if you want with PHP 5 an easy way to extract $V by reference, try this : <?php foreach ($V as $k => &$v) { $$k =& $v; } ?> It can be used to create special kind of "free args" functions that let you choose when you call them the way you send variables, and which ones. They are moreover very fast to call thanks to references : <?php function free_args (&$V) { foreach ($V as $k => &$v) { $$k =& $v; } unset ($k); unset ($v); unset ($V); // be careful that if you need to extract $k, $v or $V variables you should find other names for them in the lines above (ie. $__k, $__v and $__V) } $huge_text = '...'; $a = array ('arg1' => 'val1', 'arg2' => &$huge_text); // in this call, only $arg2 will be a true reference in the function free_args ($a); ?> Be warned that you can't write : "<?php free_args (array ('arg1' => 'val1')); ?>" because the array can't be referenced by the function, as it's not yet created when the function starts. ---- Server IP: 195.221.21.36 Probable Submitter: 82.235.104.72 ---- X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER autolearn=no version=2.64 ---- Manual Page -- http://www.php.net/manual/en/function.extract.php Edit -- http://master.php.net/note/edit/62727 Del: integrated -- http://master.php.net/note/delete/62727/integrated Del: useless -- http://master.php.net/note/delete/62727/useless Del: bad code -- http://master.php.net/note/delete/62727/bad+code Del: spam -- http://master.php.net/note/delete/62727/spam Del: non-english -- http://master.php.net/note/delete/62727/non-english Del: in docs -- http://master.php.net/note/delete/62727/in+docs Del: other reasons-- http://master.php.net/note/delete/62727 Reject -- http://master.php.net/note/reject/62727 Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#105042) next »