cphalcon icon indicating copy to clipboard operation
cphalcon copied to clipboard

[BUG]: find and findFirst fails with exception from Phalcon\Mvc\Model->toArray if there is APCU model cache enabled

Open elcreator opened this issue 4 years ago • 1 comments

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

  • Phalcon version: (php --ri phalcon) 5.0.0alpha6
  • PHP Version: (php -v) 7.4
  • Operating System: Ubuntu 20
  • Installation type: pear install
  • Zephir version (if any): 0.14.0-beta.3-0be9ad5
  • Server: Nginx
  • Other related info (Database, table schema): MySQL

Additional 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

elcreator avatar Oct 06 '21 20:10 elcreator

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.

BeMySlaveDarlin avatar Nov 09 '21 17:11 BeMySlaveDarlin