I've noticed that quote usage seems to be arbitrary in ZP's source code. For example, in full-image.php this line:
`header("Location: " . getAlbumFolder(FULLWEBPATH) . pathurlencode($_zp_current_album->name) . "/" . rawurlencode($_zp_current_image->name));`
Uses double quotes while the case statements further down use single quotes. I don't know if you guys realize this or not, but PHP evaluates everything inside double quotes while treating everything inside single quotes as a string literal.
Like in the patch attached to
#407. I've made use of PHP's double quote processing to insert the value of `$image` with out having to concatenate. But in the actual construction of `$image`, I use single quotes and concatenation for ease of reading.
I guess what I'm getting at is this. Is there a preference to quote usage in the source code?
Comments
Sometimes I use the single quotes within double quotes because it does sometime look a little cleaner to me than escaping with backslashes. Well, maybe we really should have a code formatting guide.
The only place I know of where we use them really by default is for the default values of function variables because phpdoc made some parsing problems with double quotes.
Simply, if a string does not have anything inside of it that needs to be processed ($variables, etc.), don't enclose it in double quotes. You're only causing yourself a longer load time and a more intensive process for the server.
Even more strictly speaking, it is best (for the machine, perhaps not so much for the human coder) to always concatenate variables into strings.
As for ZP source code, from what I've seen (this is taking into account the hacks that myself and others I work with have coded into my own ZP install), there's a loose preference for using single quotes, and only using double quotes when appropriate.
I don't think there is a coding preference here. (Let's not get too anal!)
I was also trying to raise the point that zebaron picked up on. Double quotes require execution time whenever they are encountered.
If you are using a quoted string in a function definition for the default value, it needs to be in single quotes. Our document extractor replaces double quotes with " in the document which looks terrible.
We are (or I am, at least) very aware of the behavior of these two quoting types, along with the so-called performance difference.
The logic in the loose rules is that the performance difference between double- and single-quotes is negligible, so worrying too much about it is simply nitpicking and we shouldn't waste time on it. See: http://spindrop.us/2007/03/03/php-double-versus-single-quotes/
More specifically, the fastest possible thing is single-quotes with concatenation, double-quotes with concatenation is nearly exactly the same, and the slowest is double-quotes with inline variables.
So really, the rule that makes the most sense is screw worrying what kind of quotes you use, but only use inline-variables in double quotes when necessary for readability when building long value-ridden strings.
Still, even remembering that it doesn't matter *much*, try to use single quotes for string literals anyway, because, well, why not? And we might shave 0.0001 seconds off each page load. Whoop-de-doo!