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

What is behind toArray() ?

Hello,

I use often toArray() method after ::find() on my model to return all objects in associative array to JSON. But I want to know where can I see the body of this method ? I don't understand how it works ? Imagine the method doesn't exist in Phalcon and I have to develop toArray() method, so what is the body of this method ?

This method, like all other implementations in the Phalcon extension was wriiten in Zephir. You could visit the github link: https://github.com/phalcon/cphalcon/blob/master/ext/phalcon/mvc/model.zep.c#L6210 . Knock yourself out... ;)

You can look the Zephir version of model::toArray() is easier to read than C++ (for me :P)

Note: Resultset\Simple and Resultset\Complex implements their own toArray methods

Good luck