php - Phalcon v.1.3. Model's onConstruct does not fire after unserialize -
phalcon 1.3 mvc model docs say:
the initialize() method called once during request, it’s intended perform initializations apply instances of model created within application. if want perform initialization tasks every instance created can ‘onconstruct’
i have model class gets serialized , implements onconstruct():
class book extends \phalcon\mvc\model { protected $a; protected $b; function onconstruct() { $this->a = 1; } function initialize() { $this->b = 2; } }
multiple instances of book
stored in memcached , loaded individually within same request.
the problem upon read memcached (i.e. unserialization) book
's onconstruct
never gets called.
i have noticed when unserializing more 1 book
in row, initialize()
gets called first instance (which correct, according docs). however, when book
#2 loaded memcached, it's $b
property null (expected 2, docs say: "apply instances of model").
questions:
- why doesn't
onconstruct()
fire @ all? - why doesn't second instance of
book
$b assigned 2?
thanks!
i may guess serialized/unserialized model considered initialized, if need additional tricks, have them after unserialization, eg. during unserialize
method.
anyway according upper logic, consider of reporting bug. if initialize method called once, should called every object unserialization or none @ all, make thing consistent.
i may test out working example.
Comments
Post a Comment