我目前的任務是升級一個PHP5之前的代碼庫以符合現代運行時。升級舊版PHP代碼 - 這些表達式是否相同?
庫中包含以下模式的幾個用途:
$foo = new foo();
foreach($foo as &$ref) {
// Do something with $ref
}
根據PHP文檔,這是PHP 5.2的非法的,將拋出一個異常(http://php.net/manual/en/migration52.error-messages.php)
我的問題是,如何修改語法以保持相同的功能,同時符合PHP 5.2+標準?如果我簡單地刪除&符號就足夠了嗎?
$foo = new foo();
foreach($foo as $ref) {
// Do something with $ref
}
'$ foo'數組中保存了哪些類型的元素? – Mantas
任何可能被迭代的對象(http://php.net/manual/en/language.oop5.iterations.php)。 – csvan
[Using foreach with SplFixedArray](http://stackoverflow.com/questions/22942860/using-foreach-with-splfixedarray) –