Re: foo[bar] _or_ foo['bar'] ?

From: Date: Tue, 13 Feb 2001 17:48:25 +0000
Subject: Re: foo[bar] _or_ foo['bar'] ?
Groups: php.general 
Request: Send a blank email to php-general+get-39451@lists.php.net to get a copy of this message
Bad practice alert!!! Derek Sivers wrote: >I had heard someone on the list say that it's always best to use quotes, >for the same reason as XHTML, where every value MUST have quotes. > >But honestly I've been using only NO-quotes all year and find it much >easier to read. And NEVER any problem! > >Also makes it easier when you need to use an array variable inside a quoted >string: > >print "Hello there $client[name]"; If your php error reporting level is set to show warnings (which it should be on your development machines) then referring to $foo[bar] will give Warning: Use of undefined constant bar - assumed 'bar' in whatever/yourscript.php on line n So php only works in this case because it couldn't find bar in it's list of constants, and guessed at the mistake you made. This just slows things down. I can't see any advantage at all to missing the quotes out. Your example could be written print "Hello there {$client['name']}"; Sorry to sound stroppy :) Cheers -- Phil Driscoll Dial Solutions +44 (0)113 294 5112 http://www.dialsolutions.com http://www.dtonline.org -----Original Message----- From: Derek Sivers <list@hitmedia.com> To: Matthias Krehl <matthias.krehl@key-work.de> Cc: php-general@lists.php.net <php-general@lists.php.net> Date: Tuesday, February 13, 2001 5:34 PM Subject: Re: [PHP] foo[bar] _or_ foo['bar'] ? > >>I'd really appreciate a clear statement whether to use better >> $foo = array('bar' => 'boing'); >> doWhatSoEver($foo[bar]); >>or >> $foo = array('bar' => 'boing'); >> doWhatSoEver($foo['bar']); > > > > > >-- >PHP General Mailing List (http://www.php.net/) >To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net >For additional commands, e-mail: php-general-help@lists.php.net >To contact the list administrators, e-mail: php-list-admin@lists.php.net > >

« previous php.general (#39451) next »