I have updated from PHP 5 to 7 and Phalcon 2 to 3. I am fetching a user from the databse using findFirst
and immediately after than I do unset($user->userid)
so the id is not shown on the result. Then I pass $user
through json_encode
.
This notice is thrown and this is the result of json_encode
:
Access to undefined property People::userid
{
"payload": {
"id": "2",
"userid": null,
"name": "Test Person",
"email": "[email protected]",
...
}
}
Before, with PHP 5 and Phalcon 2, userid wasn't showing up on the result.
The best way I found so far was to override this function in the model but I do not like this approach:
public function jsonSerialize()
{
$array = $this->toArray();
unset($array['userid']);
return $array;
}