Rasmus, Peter and I were discussing the use of ".$myvar." vs "quoted string {$myvar} more quoted string" in a separate thread. Is there a performance or compatibility advantage to using the concatenated version as you suggest in your message below? I currently use the concatenated version in all of my scripts, but Peter suggested the curly braces as a way to make the code more readable. While I agree that the curly brace method IS more readable, I want to know what the difference is before changing coding conventions. Thanks, Rich > -----Original Message----- > From: Rasmus Lerdorf [mailto:rasmus@php.net] > Sent: Sunday, November 17, 2002 12:21 AM > To: Peter Beckman > Cc: php-db@lists.php.net > Subject: Re: Passing by reference > > > PHP uses copy-on-write for by-value passes. So, if you are > not changing > the passed string inside the function there is no copy done on a > pass-by-value and this is actually faster than doing a > pass-by-reference. > > But, I'd suggest doing ".$myvar." (ie. break out of the > quoted string and > concat the var.) > > -Rasmus > > On Sun, 17 Nov 2002, Peter Beckman wrote: > > > I'm building some software that will be passing a string > variable which > > could potentially be up to 125K bytes (characters) in size. > > > > I know that passing a reference to the variable will be > much more efficient > > than copying the variable: > > > > copying, as I understand it: > > > > foo($var) > > [...later...] > > function foo ($myvar) { $sql = "insert into table > (this) values (\"$myvar\")"; } > > > > passing by reference, not copying: > > foo($var) > > [...later...] > > function foo (&$myvar) { $sql = "insert into table > (this) values (\"$myvar\")"; } > > > > A few questions: > > 1. Am I correct that PHP makes a copy of the variable > when I call the > > function with the variable, since the scope will not > be global in > > the function (unless I declare it such)? > > 2. Will I be saving some CPU cycles and memory by > passing by reference? > > 3. Is my pseudo code above correct? If not, can you > show me how one > > might pass by reference correctly? > > > > I've tested both pieces of code, but can't determine if there is a > > speed/memory difference, and I don't actually have 125K in > data handy! > > > > Thanks, > > Peter > > > -------------------------------------------------------------- > ------------- > > Peter Beckman Systems Engineer, Fairfax Cable > Access Corporation > > beckman@purplecow.com > http://www.purplecow.com/ > > > -------------------------------------------------------------- > ------------- > > > > > > -- > > PHP Database Mailing List (http://www.php.net/) > > To unsubscribe, visit: http://www.php.net/unsub.php > > > > > -- > PHP Database Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php