Open
Description
Describe the bug
Not able to initialize property in onConstruct if my model instance is from the cache
Provide minimal script to reproduce the issue
use Phalcon\Events\Manager;
use Phalcon\Mvc\Model;
class Foo extends Model
{
private Manager $eventManager;
public $name;
public function onConstruct()
{
$this->eventManager = Di::getDefault()->get('dispatcher')->getEventsManager();
}
public function afterUpdate()
{
$this->eventManager->fire('foo:updated', $this);
}
}
$foo = Foo::findFirst([
'conditions' => 'id = :id:',
'bind' => [
'id' => 1,
],
'cache' => array(
'key' => 'key.1',
)
]);
$foo->name = 'newName';
$foo->update();
//Fatal error: Uncaught Error: Typed property Foo::$eventManager must not be accessed before initialization
Expected behavior
Properly triggered event listener afterUpdate
Details
- Phalcon version: 5.0.0beta2
- PHP Version: PHP 8.0.14
- Redis Version: 5.3.5
- Operating System: Ubuntu
- Installation type: Ubuntu + Docker
- Server: Nginx
Metadata
Metadata
Assignees
Labels
Type
Projects
Status
Backlog