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 Phalcon is not using parameters type hinting?

Hello,

i wanted to understand, why Phalcon framework classes methods do not use typing hints? They make life much more easier...



98.9k

You need an IDE with auto-completion capabilities and have loaded the IDE stubs

https://github.com/phalcon/phalcon-devtools/tree/master/ide

Hmm.. i mean when you define a function, to define a parameter type:

function loopArray(array $array) {/*...*/}

https://php.net/manual/en/language.oop5.typehinting.php

Is it hard in imlementation? In many interfaces in docs you write that parameter should be instance of some interface, but actually if i impement such interface in my class and try to define parameter with some type in function - php will say that class does not match interface it implements (because in interface there is no type hint)



98.9k

We have not made research about how to implement such type hinting in C, however I think that would add a lot of overhead to the overall execution, most of the time you pass the right parameters to methods, however PHP is interpreted and it doesn't know if code is stable or it is in development and is always checking if a variable is instance of a class or implements certain interface.

Maybe avoid that is micro-optimization, however due to the fact that phalcon is fully OO and it calls hundreds/thousands of methods in every request that would make the framework slower.

Moreover, I guess we need to implement our own way of register methods + type hints, since the current ones provided by the Zend API don't provide a way to specify type hints.

Interface type hinting is it developed in new version 1.3.0 ?