PHP4: Iterate object by reference
I know I know, 4 loses support next year but I couldn't convince my co-developers to migrate from 4 to 5 so I'm stuck; we are stuck. Anyway, I need help with
foreach ($someArray as $someObject) {
// Do Changes to $someObject
}
I can't pass the changes back to the array... Help anyone? Thanks.
Re: PHP4: Iterate object by reference
Solved it by for ($i = 0; $i < count($someArray); $i++) and $someObject = &$someArray[$i] but can't I do it with foreach? It's more neat that way.
Re: PHP4: Iterate object by reference
It's the same!
PHP Code:
foreach ($c as &$v);
foreach ($c as $k => &$v);
However, PHP 5 passes objects by reference by default anyway, so this syntax is only necessary in PHP 4. The only use for it in PHP 5 is when dealing with collections of primitives, which aren't passed by reference.
Re: PHP4: Iterate object by reference
Thanks for the reply P. That gives Parse error: parse error, unexpected '&', expecting T_VARIABLE or '$'... on PHP4.4.1. Anyway I can still use the good for loop so it's semi-resolve now.
Re: PHP4: Iterate object by reference
Oh, that was added in PHP 5. My mistake. Sorry.