Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:14307 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 26021 invoked by uid 1010); 7 Jan 2005 14:34:20 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 26000 invoked from network); 7 Jan 2005 14:34:19 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 7 Jan 2005 14:34:19 -0000 X-Host-Fingerprint: 194.109.193.120 unknown Linux 2.4/2.6 Received: from ([194.109.193.120:39622] helo=mx1.moulin.nl) by pb1.pair.com (ecelerity HEAD (r4049:4050)) with SMTP id AD/5A-35138-BED9ED14 for ; Fri, 07 Jan 2005 09:34:19 -0500 Received: from localhost (localhost [127.0.0.1]) by mx1.moulin.nl (Postfix) with ESMTP id 35845C3439 for ; Fri, 7 Jan 2005 15:34:19 +0100 (CET) Received: from mx1.moulin.nl ([127.0.0.1]) by localhost (moulin [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 12930-02 for ; Fri, 7 Jan 2005 15:34:16 +0100 (CET) Received: from [127.0.0.1] (localhost [127.0.0.1]) by mx1.moulin.nl (Postfix) with ESMTP id 8EDAEC3433 for ; Fri, 7 Jan 2005 15:34:16 +0100 (CET) Message-ID: <41DE9DE2.1030701@iamjochem.com> Date: Fri, 07 Jan 2005 15:34:10 +0100 User-Agent: Mozilla Thunderbird 0.9 (Windows/20041103) X-Accept-Language: en-us, en MIME-Version: 1.0 To: php internals Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at moulin.nl Subject: use of curly braces with string interpolation. From: jochem@iamjochem.com (Jochem Maas) hi guys, I always use curly braces around vars placed in double quoted strings, I do this for 2 reasons: 1. I believe It helps the engine because the var delimitation is explicit, and this means the interpolation is (should be?) faster. 2. it looks nice (easier to read!) I have tried to test this with a simple script that does a million interations - but I cannot get it to return consistent results - one time with curlies is faster, another its slower. the (php5) script I used to test is included at the bottom of the email for those who are curious. (I haven't been able to find relevant info on either google or php.net - are there any other search engines? ;-) I am interested in knowing whether my first assumption regarding speed of interpolation is (in theory) at all correct. If any of the php gurus would give advice as to use of curly braces in interpolated strings would it be: a, always use them (its faster/better) b, only when absolutely necessary c, go away troll and figure it out for yourself (this one is tempting, n'est pas ;-) d, something I haven't had the presence of mind to think of! kind regards, Jochem. testvar = 'superduper'; $a = array('junk' => 'notbad!'); var_dump($t, $a); $strs = array(); $start = mktime(); $i = 0; do { $c = 'simplicity' + $i; $strs[] = "{$t->testvar} yadda yadda {$a['junk']} - {$c}\n"; $i++; } while ($i < 1000001); $diff = (mktime() - $start); echo "With Curlies - Total Time Taken ($diff): ".floor($diff / 60).' mins & '.($diff % 60).' secs'."\n"; $strs = array(); $start = mktime(); $i = 0; do { $c = 'simplicity' + $i; $strs[] = "$t->testvar yadda yadda $a[junk] - $c\n"; $i++; } while ($i < 1000001); $diff = (mktime() - $start); echo "Without Curlies - Total Time Taken ($diff): ".floor($diff / 60).' mins & '.($diff % 60).' secs'."\n";