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

Undefined property on lazyloaded model

In my views I pass a Group model which has many Filters. Each filter has a property part.

Looping over the Filters in volt and printing them results in a undefined property notice.

{% for filter in group.filters %}
    {{ filter.part }}
{% endfor %}

Undefined property: Phalcon\Filter::$part

Obviously this namespace is wrong and should be UniqueLoneDog\Models\Filter Dumping the model with {{ dump(filter) }} shows that it has the correct namespace however.

Anybody know what is going on or why this is happening?

object(UniqueLoneDog\Models\Filter)[151]
  public 'groupId' => string '18' (length=2)
  public 'type' => string 'predicate' (length=9)
  public 'part' => string 'test' (length=4)
...


2.6k
Accepted
answer

Found the issue.

Solution: Rename filter to groupFilter to prevent name collision.

Filter is also a class which is registerd in the DI. When the volt compiler finds a variable it first looks if it exists in the DI. If it exists the code is compiled to $this->filter->part instead of $filter->part, calling Phalcon\Filter instead of my namespace.