Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG]: Incorrect return type hint of Phalcon\Mvc\Model\Resultset::getFirst #15027

Closed
sergeyklay opened this issue May 6, 2020 · 2 comments · Fixed by #15028
Closed

[BUG]: Incorrect return type hint of Phalcon\Mvc\Model\Resultset::getFirst #15027

sergeyklay opened this issue May 6, 2020 · 2 comments · Fixed by #15028
Assignees
Labels
bug A bug report status: low Low

Comments

@sergeyklay
Copy link
Contributor

sergeyklay commented May 6, 2020

The current implementation of Phalcon\Mvc\Model\Resultset::getFirst implies that method must return a Phalcon\Mvc\ModelInterface instance or NULL:

public function getFirst() -> <ModelInterface> | null
{
if this->count == 0 {
return null;
}
this->seek(0);
return this->{"current"}();
}

But in some case, it MAY return a Phalcon\Mvc\Model\Row instance:

$robots = new Robots();
$manager = $model->getModelsManager();

/** @var \Phalcon\Mvc\Model\Query $query */
$query = $manager->createQuery('SELECT r.id FROM Robots AS r');

/** @var \Phalcon\Mvc\Model\Resultset\Simple $result */
$result = $query->execute();

/** @var \Phalcon\Mvc\Model\Row $result */
$result->getFirst();

This leads to a fatal error:

PHP Fatal error:
Return value of Phalcon\Mvc\Model\Resultset::getFirst()
must implement interface Phalcon\Mvc\ModelInterface or be null,
instance of Phalcon\Mvc\Model\Row returned in Unknown on line 0
@sergeyklay sergeyklay self-assigned this May 6, 2020
@sergeyklay sergeyklay linked a pull request May 6, 2020 that will close this issue
5 tasks
niden pushed a commit that referenced this issue May 6, 2020
@niden
Copy link
Member

niden commented May 6, 2020

Implemented in v4.0.x

@niden niden closed this as completed May 6, 2020
niden pushed a commit that referenced this issue May 16, 2020
niden pushed a commit that referenced this issue May 31, 2020
@konkov-alexey
Copy link

the same problem with getLast() method in 4.0.6

@niden niden moved this to Released in Phalcon v5 Aug 25, 2022
@niden niden added this to Phalcon v5 Aug 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A bug report status: low Low
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

3 participants