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

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?



31.9k

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.