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]: Wrong return type hint for Phalcon\Mvc\Model::count #15006

Closed
sergeyklay opened this issue May 4, 2020 · 1 comment · Fixed by #15007
Closed

[BUG]: Wrong return type hint for Phalcon\Mvc\Model::count #15006

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

Comments

@sergeyklay
Copy link
Contributor

sergeyklay commented May 4, 2020

Current return type hint of the Phalcon\Mvc\Model::count implies that method must return an integer value. But this method MAY return a Phalcon\Mvc\Model\Resultset\Simple for some cases:

public static function count(var parameters = null) -> int
{
var result;
let result = self::_groupResult("COUNT", "rowcount", parameters);
if typeof result == "string" {
return (int) result;
}
return result;
}

For example:

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

$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');
    }
}

var_dump(Invoices::count(["inv_id = 1"]));  // here is all ok
var_dump(Invoices::count(['group' => 'inv_cst_id'])); // here is an error

This leads to a fatal error:

PHP Fatal error:
Return value of Phalcon\Mvc\Model::count()
must be of the type int, object returned in Unknown on line 0
@sergeyklay sergeyklay added bug A bug report status: unverified Unverified and removed status: unverified Unverified labels May 4, 2020
@sergeyklay sergeyklay self-assigned this May 4, 2020
@sergeyklay sergeyklay linked a pull request May 4, 2020 that will close this issue
5 tasks
@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.

1 participant