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\Resultset::count bad return type

I probably found a bug because you define return type of count function as integer but I'm getting always a string value. Of course I could have something wrong in MSSQL adapter or dialect but I didn't find any function which return count value. Any hint?

I've been noticing this with get-set methods within a model even when the datatype has been set correctly on the database, I've just been casting the type directly in the get method example:

public function getId()
{
    return (int)$this->id;
}

All database values appear in PHP as strings. Phalcon doesn't do any type conversion.

Why? Adapter detect correct types for Phalcon\Db\Column so there is no reason do that when you keep values as string. However im talking about functions from Resultset:

public int count () - https://docs.phalcon.io/en/latest/api/Phalcon_Mvc_Model_Resultset.html#methods
public int count () inherited from Phalcon\Mvc\Model\Resultset - https://docs.phalcon.io/en/latest/api/Phalcon_Mvc_Model_Resultset_Simple.html

It is documented with integer but i receive string.

Sorry, I misunderstood your question.

What type of string is being returned? Is it a number string like "1" or "1,200" or "1.200"?

edited Aug '14

@quasipickle I'm encountering this currently, you state that value types aren't cast even though this behaviour (I think) should be implemented but even calling a count() as the OP has suggested returns a string

I have a Products model that has a relationship with ProductsPages and calling

var_dump($this->product->countProductsPages());

returns

string '2' (length=1)

when I'm expecting

int 2


13.4k
Accepted
answer

I've found this already reported at GitHub:

https://github.com/phalcon/cphalcon/issues/2618