Re: Constants in double-quoted strings

From: Date: Wed, 29 Oct 2008 09:01:47 +0000
Subject: Re: Constants in double-quoted strings
References: 1 2  Groups: php.internals 
Request: Send a blank email to internals+get-41548@lists.php.net to get a copy of this message
W liście Arvids Godjuks z dnia środa 29 października 2008: > People, when you will start to learn that such approach is a mess? > First, use ' ' instead of " " and format your SQL better and you > woun't > have any problems: > > <?php > define ('STATUS_ACTIVE', 1); > define ('NUM_PER_PAGE', 25); > $q = 'SELECT > ID, Name > FROM Projects > WHERE StatusID = '.STATUS_ACTIVE.' > LIMIT '.NUM_PER_PAGE.', '.$offset; > $res = mysql_query ($q); > ?> It's almost the same as original poster's version (except for $offset). > a). It's more readable without syntax highlighting > b). It's just faster. > c). It's a good style. > d). I think if that is easy to do, it would be implemented a long time ago. With regard to a and c - this is just your opinion, others might find it less readable (or indifferent). And for b - speed difference between ' and " should be negligable (esp. with opcode caches). I only worry it could break BC - people might have used "{SOMETEXT}" in strings and not expect it to be interpolated (I've done so myself). -- Paweł Stradomski

« previous php.internals (#41548) next »