NYCPHP Meetup

NYPHP.org

[nycphp-talk] Variables syntax

Aaron Fischer agfische at email.smith.edu
Fri Oct 28 17:42:30 EDT 2005


Dan Cech wrote:

>I tend to go with version D:
>
>$print_first_name = 'You said your first_name is '. 
>$_SESSION['first_name'] .'.';
>
>As you can see I use single-quotes around the 'string' portions and I 
>have modified the spacing rule a little so that I don't leave a space 
>between the 'string' portions and the . concatenation operator.
>
>There are a few reasons I use this approach, but chief among them is 
>that it makes child's play of spotting variables, especially in a 
>syntax-highlighting editor.  If they're embedded within a string they're 
>much harder to spot (for me at least).
>
>  
>

That is indeed one of the drawbacks I have noticed as well, if I embed 
the var within the string I lose the syntax highlighting which make the 
variables much harder to spot (for me as well).


>In the end it comes down to personal preference, my testing indicates 
>that the performance difference between single-quotes, double-quotes or 
>double-quotes with complex (curly) braces is not large enough to really 
>be worth considering unless you are talking about a LOT (> 100,000) 
>embedded variables.  I would suggest  going with whatever makes your 
>code the most consistent and easiest to maintain.
>
>Dan
>
>  
>
Benchmark testing is something I have on my list of "to learn about" 
stuff.  It hasn't been mentioned in the books that I have (again, I 
suppose that's further justification for more books). 

-Aaron





More information about the talk mailing list