News for hackers. Stuff that matters.
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.
Re:How PHP's foreach works by narcissus on Wednesday February 27, 2013 @09:15PM (#5296535)
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.
Re:How PHP's foreach works by Kiro on Thursday February 28, 2013 @06:23AM (#5298158)
Why do you even use references in the first place?
Re:How PHP's foreach works by smsm42 on Thursday February 28, 2013 @06:13PM (#5301743)
Data structures like trees, etc. are pretty hard to do without them, due to default array by-value semantics.