We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Model class variable problem

Hi,

Recently I upgraded Phalcon from 1.3 to 2.0.2. I assign value to an arbitrary parent class variable in initialize, then I use this parent class variable afterward. Before the upgrade, I'm able to use the parent class variable. But after the upgrade I can't. Do any of you have solution?

thanks in advance

It would be hard to help you without providing any code to explain the problem.



25.7k

Thanks for your reply Andres. Here is an abstract of my code


<?php

    // ModelBase.php
    use Phalcon\Mvc\Model;
    class ModelBase extends Model{
        protected $parent_variable = NULL;
        protected function initialize(){
            $this->parent_variable = "new value";
        }
        // ...
    }

    // Child.php
    class Child extends ModelBase{
        public function initialize(){
            parent::initialize();
        }
        // ...
    }

    // in controller
    $child = Child::findFirst();
    /*
     *  before upgrade $parent_variable is "new value"
     *   after upgrade $parent_variable is NULL
     */