On 6-Apr-2007, at 08:13, Chris Lott wrote:
echo substr("abcdef", 1);

So they naturally want to know-- why the double quotes? And there's no
good logical reason for double quotes in the example-- and there are
languages where the function could take a variable to be interpolated
that DOES need double quotes-- so it is very confusing to them.

But it's quite simple: it's a matter of preference, style, or just the mood of the programmer. Basically, there is NO difference between

echo substr("abcdef", 1);
echo substr('abcdef', 1);

Oh sure, there is some number of nanoseconds difference in evaluation time, but that's meaningless as it is an insignificant amount of time (and takes millions and millions of iterations to make any perceivable difference).

Use whichever you want. For me, I use " mostly, and usually only use ' when I am enclosing "'s to save myself having to escape them.

On 5-Apr-2007, at 14:52, Chris Lott wrote:
print 'The cost is ' . $cost;
NOT
print "The cost is $cost";

But that is certainly a silly destination to make. Both are perfectly valid and, in fact, I would argue the latter is better as it is clearer, cleaner, and shorter.

echo substr('abcdef', 1);
NOT
echo substr("abcdef", 1);

Both are perfectly fine. I'd use the latter myself as I tend to reserve the single quotes for enclosing strings containing double quotes, but that's just my preference. I certainly wouldn't deign to argue that my way was 'correct'.

--
A: You can never go too far. B: If I'm gonna get busted, it is *not* gonna be by a guy like *that*.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to