To "quote" or not to quote...

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply

To "quote" or not to quote...

Yes. I use quotes with $arrays.
9
90%
No. I do not use quotes with $arrays.
1
10%
 
Total votes: 10

Gen-ik
DevNet Resident
Posts: 1059
Joined: Mon Aug 12, 2002 7:08 pm
Location: London. UK.

To "quote" or not to quote...

Post 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?
Last edited by Gen-ik on Thu Nov 06, 2003 6:15 pm, edited 1 time in total.
itbegary
Forum Commoner
Posts: 34
Joined: Sun Jan 05, 2003 2:50 am

Post 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
McGruff
DevNet Master
Posts: 2893
Joined: Thu Jan 30, 2003 8:26 pm
Location: Glasgow, Scotland

Post by McGruff »

Always, always ['quote'] an array key.
User avatar
Sevengraff
Forum Contributor
Posts: 232
Joined: Thu Apr 25, 2002 9:34 pm
Location: California USA
Contact:

Post 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.
d3ad1ysp0rk
Forum Donator
Posts: 1661
Joined: Mon Oct 20, 2003 8:31 pm
Location: Maine, USA

Post by d3ad1ysp0rk »

so now im confused..

whats better?

$array["foo"];
or
$array['foo'];
User avatar
infolock
DevNet Resident
Posts: 1708
Joined: Wed Sep 25, 2002 7:47 pm

Post by infolock »

always quote the field unless it's the specific #...

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

i use both myself.
McGruff
DevNet Master
Posts: 2893
Joined: Thu Jan 30, 2003 8:26 pm
Location: Glasgow, Scotland

Post 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.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

http://www.php.net/manual/en/language.t ... rray.donts
obey the manual.

obedience brings victory
Jem'Hadar motto
Post Reply