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\CriteriaInterface::getLimit() #15004

Closed
sergeyklay opened this issue May 4, 2020 · 1 comment · Fixed by #15005
Closed
Assignees
Labels
bug A bug report status: low Low

Comments

@sergeyklay
Copy link
Contributor

sergeyklay commented May 4, 2020

The documentation says:

Returns the limit parameter in the criteria, which will be an integer if
limit was set without an offset, an array with 'number' and 'offset' keys
if an offset was set with the limit, or null if limit has not been set.

But actual return type hint declared as string | null (not int | array | null):

/**
* Returns the limit parameter in the criteria, which will be an integer if
* limit was set without an offset, an array with 'number' and 'offset' keys
* if an offset was set with the limit, or null if limit has not been set.
*
* @return string|null
*/
public function getLimit() -> string | null
{
var limit;
if !fetch limit, this->params["limit"] {
return null;
}
return limit;
}

This leads to a fatal error:

<?php

use Phalcon\Di;
use Phalcon\Di\FactoryDefault;
use Phalcon\Db\Adapter\PdoFactory;
use Phalcon\Mvc\Model;
use Phalcon\Mvc\Model\Criteria;

$options = ['dbname' => '/tmp/test.sqlite'];

Di::reset();

$container = new FactoryDefault();
Di::setDefault($container);

$container->setShared(
    'db',
    (new PdoFactory())->newInstance('sqlite', $options)
);

class Invoices extends Model {
    public $inv_id;
    public $inv_cst_id;
    public $inv_status_flag;
    public $inv_title;
    public $inv_total;
    public $inv_created_at;

    public function initialize()
    {
        $this->setSource('co_invoices');
    }
}

$criteria = new Criteria();
$criteria->setDI($container);
$criteria
    ->setModelName(Invoices::class)
    ->limit(10, 15)
;

var_dump($criteria->getLimit());
PHP Fatal error:
Return value of Phalcon\Mvc\Model\Criteria::getLimit()
must be of the type string or null, array returned
@sergeyklay sergeyklay added bug A bug report status: unverified Unverified and removed status: unverified Unverified labels May 4, 2020
@sergeyklay sergeyklay linked a pull request May 4, 2020 that will close this issue
5 tasks
@sergeyklay sergeyklay self-assigned this May 4, 2020
@sergeyklay
Copy link
Contributor Author

Fixed in 4.0.x branch

@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.

2 participants