Reply to Re: single quotes, double quotes and "undefined index"

Your name:

Reply:


Posted by Toby A Inkster on 07/15/07 19:58

Michael Fesser wrote:

> Didn't test it, but according to the manual it should work

It will work, yes, but it's unwise, as you'd be skating on very thin ice.

echo $foo[bar];
echo "{$foo[bar]}";

will both use the constant 'bar' instead of the string 'bar' if it exists.
It's very easy to slip up in this area, so safer to always quote strings
used as array indices.

PHP is known to change its syntax from time to time, and may well become
less forgiving in the future with regard to something like:

echo "$foo[bar]";

and I'd imagine such a bug may be very tricky to track down.

--
Toby A Inkster BSc (Hons) ARCS
[Geek of HTML/SQL/Perl/PHP/Python/Apache/Linux]
[OS: Linux 2.6.12-12mdksmp, up 24 days, 23:34.]

demiblog 0.2.0 Released
http://tobyinkster.co.uk/blog/2007/06/28/demiblog-0.2.0/

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация