note 96927 added to functions.arguments

From: Date: Tue, 23 Mar 2010 17:37:11 +0000
Subject: note 96927 added to functions.arguments
Groups: php.notes 
Request: Send a blank email to php-notes+get-167320@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?’ 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 ---- Server IP: 69.147.83.197 Probable Submitter: 93.173.68.0 ---- Manual Page -- http://www.php.net/manual/en/functions.arguments.php Edit -- https://master.php.net/note/edit/96927 Del: integrated -- https://master.php.net/note/delete/96927/integrated Del: useless -- https://master.php.net/note/delete/96927/useless Del: bad code -- https://master.php.net/note/delete/96927/bad+code Del: spam -- https://master.php.net/note/delete/96927/spam Del: non-english -- https://master.php.net/note/delete/96927/non-english Del: in docs -- https://master.php.net/note/delete/96927/in+docs Del: other reasons-- https://master.php.net/note/delete/96927 Reject -- https://master.php.net/note/reject/96927 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#167320) next »