Page 1 of 1

To "quote" or not to quote...

Posted: Thu Nov 06, 2003 5:53 pm
by Gen-ik
...that is my question.


Some people recommend using quotes with arrays like so.. $var["bob"] ..other people recommened using the quoteless method.. $var[bob] ..both have valid reasons why, and why not, their method is the best one.


So, do you quote or don't you quote?
What problems have you encountered with quoting or without quoting?

Posted: Thu Nov 06, 2003 6:05 pm
by itbegary
I've noticed that everytime I forget to quote something I get a warning about assuming it's literal text. I'm assuming you disabled warnings... :)

Anyways, I always quote the literal text and single quote anything that I don't want mangled in any way. Sometimes I use things like Micro$oft or $un in the string and I get Micro or nothing at all... :) So that's wy I single quote it sometimes...

That's my $0.02 worth... Probably only worth a penny though...

Gary Smith

Posted: Thu Nov 06, 2003 6:33 pm
by McGruff
Always, always ['quote'] an array key.

Posted: Thu Nov 06, 2003 6:38 pm
by Sevengraff
McGruff wrote:Always, always ['quote'] an array key.
I must agree, using quotes is tho only way to go. I believe php.net has stated this somewhere.

Posted: Thu Nov 06, 2003 6:56 pm
by d3ad1ysp0rk
so now im confused..

whats better?

$array["foo"];
or
$array['foo'];

Posted: Thu Nov 06, 2003 7:06 pm
by infolock
always quote the field unless it's the specific #...

ie : array['bob'];
or : array[0];

i use both myself.

Posted: Thu Nov 06, 2003 7:18 pm
by McGruff
LiLpunkSkateR wrote:so now im confused..

whats better?

$array["foo"];
or
$array['foo'];
Either works.

Numerical keys $arr[3] etc don't need quoting, as mentioned above.

Posted: Thu Nov 06, 2003 9:17 pm
by volka
http://www.php.net/manual/en/language.t ... rray.donts
obey the manual.

obedience brings victory
Jem'Hadar motto