Using a CApplicationComponent may not be appropriate if the utility function is used "often" (because Yii::app()->myutils results in a function call to find the component, whereas the use of a utility class does not).

CHtml was mentionned as an example of a Utility class, not something to hack !

To extend/override CHtml, create a derived class and use that instead ;-).

@le_top - you make a fair point about the overhead from using a component, I don't really have figures to see how much difference that would make so I can't comment further.

You quoted CHtml as a good example of using static/singleton (which it is), but singletons have their pitfalls. Singletons really just create globals, but with a prettier way to access them.

You mention creating a derived class of CHtml - that's good, but as CHtml is called explicitly, anything that uses the CHtml methods you want to override would have to be overridden as well (e.g. CGridview)!

In the past I've had to rebuild entire widgets because they call CHtml directly instead of using a configurable component, so I was just offering an alternative - and using CHtml as an example of something that's impossible to really replace in Yii without replacing everything that uses it.

Either way, I agree that your solution is definitely valid and an improvement on dumping a load of functions straight into the top level, I was just presenting another case/option.

@hippyjim:
I agree that adapting core classes to application requirements is not always an easy job, even if in most cases Yii is pretty flexible.
In the case of self-managed utility classes the comment of its limited flexibility in terms of adapting that class is limited because you have control over your source.

CApplicationComponent is something I use quite often - I even built a CApplicationComponentProxy to select the right component depending on the user configuration.

A utility class should be for "immutable" functionnality - I have functions in it for converting database time to system time for instance. Formatting is done in a Formatter component that replaces the standard one.

While it is a hack, it is still possible to replace "CHtml" for all classes if you explicitally load a replacement CHtml class before the autoloader looks for CHtml. A simple include of the file in your 'index.php' should do the trick.
If you are using 'Yiilite', you need to rebuild Yiilite excluding the class that you want to replace.

If you just want to make some minor changes to CHtml while keeping the same class name, you can have a look at Patching php code without changing the original code. If that patch method can be avoided it is preferable, but avoiding a change to the original code might be preferable to allow easy vendor updates.

Components, utility classes and patches all have their use, in that preferred order ;-).