["HTTP_POST"} versus ['HTTP_POST']

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
I've inherited a huge, rambling site with numerous lines containing
php.net says it should be single inverted commas, not double, yet
everything seems to work.  As it would be a considerable amount of
work to change everything, can I safely leave things as they are?

Re: ["HTTP_POST"] versus ['HTTP_POST']

joboils@hotmail.com kirjoitti:
Quoted text here. Click to load it

I'm sure you've misinterpreted the manual. The syntax above, with double  
quotes is prefectly fine. All it does is that it delimits a string  
literal, for this puropuse double quotes and single quotes are just  
fine. The reason single quotes is _preferred_ (but not required) is that  
in this case it's slightly faster. You see, double quoted strings may  
containt php variables that are replaced with the string values of the  
variables. Single quoted strings do not have this quality, and that is  
the reason they work a little bit faster than double quoted strings.

But  like the wise man said: if it works, don't fix it. You can leave it  
just like that and be cool with it. I'm sure the possible improvement in  
performance that you'd gain from changing each double quote to single  
quote is nominal, you'll do nothing but waste your time.

Finally a little example to demonstrate the difference.

$cat = "Garfield";

echo "That $cat is so funny!"; // Double quotes
// This will print: That Garfield is so funny!
// $cat is changed into its value.

echo 'That $cat is so funny!'; // Single Quotes
// This will print: That $cat is so funny!
// No changes are made, printed literally as it's written.


"Wikipedia on vähän niinq internetin raamattu, kukaan ei pohjimmiltaan
usko siihen ja kukaan ei tiedä mikä pitää paikkansa." -- z00ze

Re: ["HTTP_POST"] versus ['HTTP_POST']

On Sat, 07 Jul 2007 11:55:00 +0300, Rami Elomaa

Quoted text here. Click to load it

Thanx to both of you.

Re: ["HTTP_POST"} versus ['HTTP_POST']

joboils@hotmail.com wrote:
Quoted text here. Click to load it

In this case there is no difference between single and double.

You cannot break anything by changing it to single quotes and it's no
work at all, just do a global replace of one for another.

The only case a replace can break if there is a string like this:

    'I am using $_SERVER["HTTP_POST"] variable'

will convert to:

    'I am using $_SERVER['HTTP_POST'] variable'

and break the code into syntax error


Site Timeline