[TYPO3-dev] [TYPO3-core] New TYPO3 Coding Guidelines

Christopher Torgalson bedlamhotel at gmail.com
Fri Jul 10 01:38:57 CEST 2009


On Thu, Jul 9, 2009 at 2:42 PM, Ernesto Baschny [cron
IT]<ernst at cron-it.de> wrote:
> Christopher Torgalson schrieb:

<snip>

>> If you want to do that, you could also use sprintf--it makes for nice
>> and readable code up to a point (after 7 or 8 replacements, it's can
>> be pretty hard to read...):
>>
>> $format = 'SELECT %s FROM %s WHERE %s LIMIT %d';
>> $query = sprintf($format, $tables, $from, $where, $limit);
>
> My tests show this on my environment (PHP 5.2.0 with eaccelerator):
>
> $a = 'test2';
>
> 100.00%  $tmp = 'test ' . $a;
> 105.64%  $tmp = "test $a";
> 174.98%  $tmp = sprintf('test %s', $a);
> 180.87%  $tmp = str_replace('#a#', $a, 'test #a#');
>
> Slight difference. Isn't worth a change, as the first one is the most
> "readable" one. I also like the "template-based" sprintf, but it
> shouldn't be used if you are going to loop through it 50.000 times. :)


Thanks Ernesto, that's a useful tid-bit...

-- 
Christopher Torgalson
http://www.typo3apprentice.com/




More information about the TYPO3-dev mailing list