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

Ernesto Baschny [cron IT] ernst at cron-it.de
Thu Jul 9 23:42:52 CEST 2009


Christopher Torgalson schrieb:

> On Thu, Jul 9, 2009 at 1:29 PM, Vladimir
> Podkovanov<admin at sitesfactory.ru> wrote:
>>> Sure, it is right if many editors does not hightlight vars in string.
>>> However in Zend Studio IMHO more readable when var inside string as I
>>> can see all SQL request and don't try to concat parts in my mind in
>>> order to see whole request ;)
>>>
>> Example:
>>
>> "where login = '$login'"
>> vs
>> 'where login = \'' . $login . '\''
> 
> 
> 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. :)

Cheers,
Ernesto




More information about the TYPO3-dev mailing list