You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is related to how typed properties works in php7.4+ and the way we initialize models.
For now, to fix this issue, we need to change the logic of models initializasion in Phalcon\Mvc\Model::unserialize().
Highly likely it will cause bbc.
Describe the bug
find and findFirst fails with exception from Phalcon\Mvc\Model->toArray if there is APCU model cache enabled.
To Reproduce
[06-Oct-2021 23:20:27 Europe/Kiev] PHP Fatal error: Uncaught Error: Typed property Auth\Models\User::$email must not be accessed before initialization in /home/project/includes/BaseModel.php:33
Stack trace:
#0 /home/project/includes/BaseModel.php(33): Phalcon\Mvc\Model->toArray()
#1 [internal function]: BaseModel->toArray()
#2 [internal function]: Phalcon\Mvc\Model->serialize()
#3 [internal function]: serialize()
#4 [internal function]: Phalcon\Mvc\Model\Resultset\Simple->serialize()
#5 [internal function]: serialize()
#6 [internal function]: Phalcon\Storage\Serializer\Php->serialize()
#7 [internal function]: Phalcon\Storage\Adapter\AbstractAdapter->getSerializedData()
#8 [internal function]: Phalcon\Storage\Adapter\Apcu->set()
#9 [internal function]: Phalcon\Cache->set()
#10 [internal function]: Phalcon\Mvc\Model\Query->execute()
#11 /home/project/includes/BaseModel.php(112): Phalcon\Mvc\Model::findFirst()
#12 /home/project/modules/auth/controllers/LoginController.php(22): BaseModel::findFirst()
#13 [internal function]: Auth\Controllers\LoginController->login in /home/project/includes/BaseModel.php on line 33
Steps to reproduce the behavior:
https://github.com/elcreator/phalcon-demo/blob/main/includes/BaseModel.php#L117 - uncomment this to see the failure.
It works if these lines remain commented (i.e. when cache parameter is absent).
Refer to https://docs.phalcon.io/4.0/en/db-models-cache example as cache was taken from this doc
Expected behavior
Error should not be thrown
Details
php --ri phalcon
) 5.0.0alpha6php -v
) 7.4Additional context
https://github.com/elcreator/phalcon-demo follow readme to get environment with DB to reproduce this issue when trying to login
Get familiar with https://github.com/elcreator/phalcon-demo/blob/main/modules/auth/controllers/LoginController.php
https://github.com/elcreator/phalcon-demo/blob/main/modules/auth/models/EmailUser.php
https://github.com/elcreator/phalcon-demo/blob/main/modules/auth/models/User.php
The text was updated successfully, but these errors were encountered: