On Thu, 2002-03-07 at 11:23, Markus Fischer wrote: > On Thu, Mar 07, 2002 at 08:02:17PM +0100, [EMAIL PROTECTED] wrote : > > On Thu, 7 Mar 2002, Andrey Hristov wrote: > > > > > You probably do: > > > $some_len = strlen(&$some_str); > > > > right. > > > > > you do not need to use &. Probably $some_str is passed by reference > > > without &. > > > > What do you mean by probably? I mean, the reason for me to use the > > call-by-reference is the performance... > > > > I'm not on php-dev, so please reply to my personal adress ;) > > The not obvious thing is that references _are not_ faster. It > is was Andi always has told us and it is what people said who > did testing. Testings were posted to this list a while ago > and performance of references was also discussed in the > german php newsgroup. PHP is not C; references are > not like C pointers; they are not faster.
This was my understanding too, until I tested it a few seconds ago. But when I created a large string and did the following: <?php error_reporting(E_ALL); $bigstring = implode("\n", file('/home/torben/work/phpdoc/en/appendices/reserved.xml')); function with_ref() { global $bigstring, $with_ref_len; $with_ref_len = strlen(&$bigstring); } function without_ref() { global $bigstring, $without_ref_len; $without_ref_len = strlen($bigstring); } speedtest(array('with_ref', 'without_ref'), 1000); echo "With Ref len: $with_ref_len; Without ref len: $without_ref_len\n"; ?> I got: Warning: Call-time pass-by-reference has been deprecated - argument passed by value; If you would like to pass it by reference, modify the declaration of strlen(). If you would like to enable call-time pass-by-reference, you can set allow_call_time_pass_reference to true in your INI file. However, future versions may not support this any longer. in /home/torben/public_html/phptest/__phplist.html on line 22 Running with_ref() 1000 times... 0.064337968826294 seconds Running without_ref() 1000 times... 18.39444899559 seconds Results: with_ref_1: 0.064337968826294 without_ref_2: 18.39444899559 With Ref len: 448490; Without ref len: 448490 ...which seems to indicate that under some circumstances passing by ref is indeed much faster. I could be missing something though--I haven't had breakfast yet and I'm not too smart in the morning. :) Cheers, Torben -- Torben Wilson <[EMAIL PROTECTED]> http://www.thebuttlesschaps.com http://www.hybrid17.com http://www.inflatableeye.com +1.604.709.0506 -- PHP Development Mailing List <http://www.php.net/> To unsubscribe, visit: http://www.php.net/unsub.php