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

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

 



Thanks, well that's why I was asking because we just let a guy go for doing
stuff like that among other obvious bad coding issues and terrible logic.
The guy didn't know what he was doing but, I wanted to make sure I wasn't
out of my mind by pointing that out. I am new to Zend Studio so I don't
know if it was picking that up from other bad code in the project and
suggesting for "consistency" sake or what. I definitely thought it was
weird.

Thanks again.

On Thu, May 31, 2012 at 10:54 AM, Daniel Brown <danbrown@xxxxxxx> wrote:

> 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/
>

[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