PHP 8.5.0 Alpha 2 available for testing

Voting

: five minus five?
(Example: nine)

The Note You're Voting On

owk dot ch199_ph at gadz dot org
19 years ago
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.

<< Back to user notes page

To Top