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

\Phalcon\Mvc\Model\ResultsetInterface not traversable/iterable

This is only a minor niggle as the code works, but the return class definition from Model::find() (and others) is declared as \Phalcon\Mvc\Model\ResultsetInterface but it's only at the \Phalcon\Mvc\Model\Resultset that this is implemented along with \Iterator etc.

This is causing my IDE PhpStorm to throw a not traversable warning for a \Phalcon\Mvc\Model\ResultsetInterface (which appears to be correct).

So my question is why does find() declare the return as ResultsetInterface and not Resultset? Or can the ResultsetInterface be declared as iterable somehow?

Dave

edited Jun '17

Hey, I have a base model class that everything inherits, and I simply override the methods there with proper hinting. This has the additional benefit of having the proper class type being returned, not just a generic Model (in code hinting)

class BaseModel extends \Phalcon\Mvc\Model
{
    /**
     * @param null|array $params
     * @return $this[]
     */
    public static function find(...$params) {
        return parent::find(...$params);
    }

    /// etc...
}

But you're probably right, ResultsetInterface SHOULD implement Iterable