NYCPHP Meetup

NYPHP.org

[nycphp-talk] single quote vs. double quote

Paul Houle paul at devonianfarm.com
Tue Apr 3 19:31:58 EDT 2007


Anirudh Zala wrote:
> #2 When your data is static, use 'single quotes' to tell PHP to use it "as it 
> is", if dynamic then should not be enclosed by ANY quote.
>
> #3 If you have mixture of static+dynamic then use $dynamic.'I am static' style 
> to concat dynamic and static data.
>   
    If I wanted to code like that,  I'd be coding in Java.

    I did a long stint of programming in Perl,  which offers you about 
30,000 ways to quote text.

    Here are my rules for PHP.

    (1) Use ?>...some HTML...<?php as much as feasible
    (2) Avoid heredoc -- it's particularly treacherous in PHP
    (3) Use " in most situations.  Use \ to escape ", $ and \.
    (4) Make a habit of writing {$like_this}

    Convention (3) turns out to be an effective convention 
cross-language.  Double quotes work the same way in shell scripts,  perl 
scripts and other places.  It might not be the most elegant syntax, but 
it works well.



More information about the talk mailing list