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

toArray method

Hello, in toArray method says : "We only assign values to the public properties".

Why only public props ? I think it will be more comfortably to set protected attributes to a Model through setters.

afaik toArray uses the info from columnMap, so having setters/getters wont change it's behaviour (at least it hasnt for me)



1.4k

No, it doesnt work if props are protected/private, only if public.



1.4k

It says https://docs.phalcon.io/en/3.2/db-models#properties-setters-getters that it should be work. But if My class extends from MongoCollection its not working, toArray cant working with protected/private props...

edited Jul '17

Oh so you mean mongocollection then yea i think you need public, i think it's zephir bug :/

Nothing more really ned to add https://github.com/phalcon/zephir/issues/1245

Only fix i see you can add toArray method in php - https://github.com/phalcon/cphalcon/blob/master/phalcon/mvc/collection.zep#L1612



1.4k

Maybe use Reflection in zep ?

Oh so you mean mongocollection then yea i think you need public, i think it's zephir bug :/

Nothing more really ned to add https://github.com/phalcon/zephir/issues/1245

Only fix i see you can add toArray method in php - https://github.com/phalcon/cphalcon/blob/master/phalcon/mvc/collection.zep#L1612

That might be a way or maybe casting it to array could be enough.