Hello folks.
We are considering to use Phalcon as the base for our new Project. While playing arround with the Models I realized that all values inside the Model classes are strings. That is no problem but when sending out the reponses as JSON (using json_encode), numbers (and booleans) will be encoded as strings too. We used the phalcon-devtools for generating the Model classes and the datatypes are correctly added to the PHP-DocBlock:
/**
* @var integer
*
*/
protected $test1;
/**
* Method to set the value of field test1
*
* @param integer $test1
*/
public function setTest1($test1)
{
$this->test1 = $test1;
}
/**
* Returns the value of field test1
*
* @return integer
*/
public function getTest1()
{
return $this->test1;
}
We could use some custom json_encode function or set the response arrays manually by adding type casts to the getters (and setters) and setting all properties by hand.
What do you recommend to encode the model properties in their "correct datatype" in the JSON reponse? Is there a performant "Phalcon way" to achieve this? Or maybe I'am missing something obvious?
To clarify my question: Is there a way to enforce the model properties to be used as the annotated datatypes?
Thank you for your incredible work.