Functions in Yii, good or bad?

PHP is a procedural and object oriented language, and even though the language has started to focus more on objects that is only because function are a very strong feature of the language.

So the thing I’d like to discuss is why not convert classes that have only static methods (CHtml, some of YiiBase’s methods and similar classes) into functions. My main argument about this is that classes with only static methods is (if not a bad practice) a misuse of classes because all of the methods are just functions grouped in a convenient way.

Primarily we use classes because (unlike function) they can be extended, changing the way the class works, but in CHtml’s case the only methods we can extend (to get this effect) are “activeId()” and “activeName()”, but none of the others because there is rarely a need to change them.

Another example can be with CActiveDataProvider and CArrayDataProvider, we can have a function called data_provider($data) and it returns one of the two depending on $data, or converts the data to be used by CDataProvider directly.

Well these are just simple examples and ideas, my question is why not use function in these situations or others?

Having classes with static functions is also a convenient way of namespacing, so that there are no potential clashes with other functions.

I personally am a great believer in OOP, and as such think polluting the global namespace is a bad idea - I’m much happier with the move away from procedural styles.

Additionally, I can see no possible benefit from converting to functions…

php has also closures, and a lot of new feature in php5.4. Why dont adopt all these new amazing stuffs? Like new arrays for example. You want come back in php4? Why? I came from phpDay in Verona (Italy) right now. Php is more than functions and static methods. Is also design pattern. Tests. Standard. There are a lot of reason to go on php 5.3 or php 5.4 version.

Function can be used with namespace, so can constants. What I’m trying to say is that both stiles have they’re advantages and disadvantages so we should use them accordingly.

I’m not against PP or OOP, I just belive that they should work togerther, because they were design for diffrent things.