note 96927 modified in functions.arguments by danbrown
| From: | danbrown@php.net | Date: | Tue, 23 Mar 2010 18:20:05 +0000 |
| Subject: | note 96927 modified in functions.arguments by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-167323@lists.php.net to get a copy of this message | ||
Hey,
I started to learn for the Zend Certificate exam a few days ago and I got stuck with one
unanswered-well question.
This is the question:
âAbsent any actual need for choosing one method over the other, does passing arrays by value to
a read-only function reduce performance compared to passing them by reference?â
This question answered by Zend support team at Zend.com:
"A copy of the original $array is created within the function scope. Once the function
terminates, the scope is removed and the copy of $array with it." (By massimilianoc)
Have a nice day!
Shaked KO
--was--
Hey,
I started to learn for the Zend Certificate exam a few days ago and I got stuck with one
unanswered-well question.
This is the question:
âAbsent any actual need for choosing one method over the other, does passing arrays by value to
a read-only function reduce performance compared to passing them by reference?â
The answers speaks about Lazy Copy Mechanism\Copy-on-Write.
I tried to search at php.net, zend forums and google.com about how this mechanism works, and
unfortunately there were no results.
I`m trying to understand what is the deference between passing array by value (when readonly) and
passing array by reference, and why passing the array by value is faster?
My example:
function test($array)
{
echo $array[0]." ".$array[1];
}
$arr=array(1,2);
test($array);
because the $array is read-only, the $arr was not copy, right? so where $array point to?
This question answered by Zend support team at Zend.com:
"A copy of the original $array is created within the function scope. Once the function
terminates, the scope is removed and the copy of $array with it." (By massimilianoc)
Hope you'll understand the meaning of Lazy Copy Mechanism\Copy-on-write.
More question can be asked at:
http://forums.zend.com/viewtopic.php?f=63&t=5879&start=0
Have a nice day!
Shaked KO
http://php.net/manual/en/functions.arguments.php