Re:How PHP's foreach works
by xkcdfanboy on Wednesday February 27, 2013 @08:20PM
(#5296335)
I can't count the times that references have caused wierd errors in my PHP code. Definitely a good recommendation.
[ Parent
| on HN ]
I hear ya. In fact, I got burned by that problem enough times to make a test for it in my PHPCS 'coding standard'... which is basically a handful of standards that look for my stupid, repeated, coding errors :)
Re:How PHP's foreach works
by function_seven on Wednesday February 27, 2013 @09:37PM
(#5296609)
My own standard is this:
foreach ($array as & $ref) {
// Do something with $ref
} unset ($ref);
i.e. put the `unset()` call on the same line as the closing brace, forever "welding" it to that block.Why do you even use references in the first place?