We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

foreach loop result set

$list = AdminMenu::find([
  'conditions' => "pid = ?0",
  'bind' => [$pid],
  'order' => 'sort asc, id asc',
]);
Next, I want to loop the result set
foreach ($list as &$value) {
    $value->up_title = '无';
}

tip:
( ! ) Fatal error: Uncaught Error: An iterator cannot be used with foreach by reference in C:\wamp64\www\admin\app\controllers\MenuController.php on line 30
( ! ) Error: An iterator cannot be used with foreach by reference in C:\wamp64\www\admin\app\controllers\MenuController.php on line 30
line 30 is foreach ($list as &$value) {

what should I do? To cyclic operation result set

edited Aug '16

By default any object in php is passed as reference, no need to add &

Also if it's for displaying only, not editing, consider using arrays like toArray() method on resultset.

edited Aug '16

do not add &
No effect on acb
I can not use toArray()
Because I want to use some of the features of the object

By default any object in php is passed as reference, no need to add &

Also if it's for displaying only, not editing, consider using arrays like toArray() method on resultset.