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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, May 31, 2012 at 12:48 PM, Tristan <sunnrunner@xxxxxxxxx> 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/

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux