quoting keys

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
php_silicon_valley
Forum Newbie
Posts: 3
Joined: Mon May 12, 2008 5:28 pm

quoting keys

Post by php_silicon_valley »

Hi,

Is it desirable, necessary or a bad idea to double quote variables in key. Is this a good or bad idea? $array["$a"]
I get that $array['a'] is a good idea, but not sure if that concept extends to variables. Pros and cons please?
Thx!
php_silicon_valley
Forum Newbie
Posts: 3
Joined: Mon May 12, 2008 5:28 pm

Re: quoting keys

Post by php_silicon_valley »

oh my gosh pleeeeeeeeeeeeeeeeease help-- my manager :evil: is after me on this!
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: quoting keys

Post by Christopher »

I think quoting variables (e.g., $array["$a"]) that are not to be expanded in a larger string is not a good practive. mainly it is simply not necessary (i.e., "$a" == $a). The confusion is perhaps because with string literal keys should always be quoted (e.g., $array['a']) but unquoted keys was once allowed.
(#10850)
php_silicon_valley
Forum Newbie
Posts: 3
Joined: Mon May 12, 2008 5:28 pm

Re: quoting keys

Post by php_silicon_valley »

Thx!!!! :D
Post Reply