Re: [foreach] - is it proper to...

From: Date: Thu, 31 May 2012 16:54:09 +0000
Subject: Re: [foreach] - is it proper to...
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-318046@lists.php.net to get a copy of this message
On Thu, May 31, 2012 at 12:48 PM, Tristan <sunnrunner@gmail.com> wrote: > I'm using Zend Studio and it had a suggestion that I do a foreach as such > > foreach($entry as $entry){ > > } .... which would be the same as foreach ($entry) --- a syntax option that doesn't exist, but would be ideal. > foreach($entries as $entry){ > > } I prefer this method as well, as redefining a variable with its own name, whether in a foreach loop or elsewhere, not only feels clunky, but could also quite easily cause issues. Imagine, for example, that not all versions of PHP support the same-variable option, be it by bug, deprecation, et cetera. It would be a pain to track down the bug in your code. > they both seem to work but, from a readability standpoint and just makes > more sense to me to use method 2. Is it bad practice to go with the 1st > method of coding or preferred? To be honest, I didn't know Zend was suggesting that, but if you want my lowly opinion --- use the second (and your preferred) method. I can't think of an instance in my experience where I found another programmer's code using the first method either. -- </Daniel P. Brown> Network Infrastructure Manager http://www.php.net/

« previous php.general (#318046) next »