I am currently tasked with upgrading a library of pre-PHP5 code to conform with modern runtimes.
The library contains several uses of the following pattern:
$foo = new foo();
foreach($foo as &$ref) {
// Do something with $ref
}
According to the PHP documentation, this is illegal as of PHP 5.2, and will throw an exception (http://php.net/manual/en/migration52.error-messages.php)
My question is, how do I change the syntax to maintain the same functionality, while conforming to PHP 5.2+ standards? Does it suffice if I simply remove the ampersand?
$foo = new foo();
foreach($foo as $ref) {
// Do something with $ref
}