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

Model events as protected methods?

I'm using Phalcon 4.0.4 now and looking at documentation, it is suggested to use public methods when adding events like beforeUpdate. But looking at cphalcon source code it seems, that these methods are called from inside model only. So my question is, will there be any drawback when using protected function beforeUpdate() instead of public function beforeUpdate? And does this apply to all model events?

Since the ModelInterface does not specify these methods, and as you've said, all calls to these events are fired from the model itself, so yes, it should not be a problem at the moment.

But in theory, the Phalcon team could change this at any time, so it might be a better idea to just mark these methods as @internal with docblocks...

edited Mar '20

you can type hint the model or not, it is irrelevant. Type hinting doesn't mean injecting. For the dependencies to be injected, the function/method must be resolved through the container, which isn't the case for observers callback fuctions McDVOICE