【问题标题】:ArrayIterator::valid not worksArrayIterator::valid 不起作用
【发布时间】:2013-06-18 00:21:16
【问题描述】:

我有一个 Propel 集合,并尝试迭代它。我使用 Propel 集合 getIterator() 方法来获取 ArrayIterator 的实例。 所以,在我的代码中:

$medicos = $query->find();
$it = $medicos->getIterator();
while($it->valid()){
     [...]
}

但我的代码在循环条件下失败了:

致命错误:在非对象上调用成员函数 valid() ...

现在,当我执行时:

$it = $medicos->getIterator();
die($it);

打印 1,因此,“真实”。发生了什么 ?。任何想法 ?。 谢谢!。

【问题讨论】:

    标签: php arrays collections iterator propel


    【解决方案1】:

    我发现了错误。人为错误 xD。 在此期间,我将下一个元素称为:

    $it = $it->next()
    

    我不得不使用:

    $it->next()
    

    循环在第二遍时中断。

    【讨论】:

      猜你喜欢
      • 2017-09-12
      • 1970-01-01
      • 2017-03-16
      • 2017-10-04
      • 1970-01-01
      • 2011-05-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多