Why Dynamic add a property of the model instance is protected

class Robot extends Model {}

$r = Robot::findFirst("id = '1'");
$r->count = array('a','b','c','d');

var_dump($r):
protected '_related' => 
        array (size=1)
          'count' => 
            array (size=4)
              ...

What's your question?



16.0k

I want to need property:count, but it access protected

Phalcon models have magic getters and setters, so when you call

$Robot->count = ['a','b','c','d'];

You're actually calling

$Robot->__set('count',['a','b','c','d']);

Even though it's protected, you can still set it.

Read through the documentation about related models - it might give you some insight.