workaround for the lack of late static binding in php

I made a new class MyCHtml.php which extends CHtml.php, it overwrites the tag method to do text translation right there. But: when using MyCHtml (ex.: MyCHtml::activeLabelEx) the new tag method is not used, since it's called statically within CHtml and PHP does not yet support late static binding.

Is there a good solution to solve this problem?

I can only come up with this:

  • Copy CHtml to MyCHtml and do the desired changes (not good)

  • or change Yii so that no static calls are made anymore ($this->tag instead of self::tag) and then work with an object, one could have a static factory method, example: MyCHtml::fac()->activeLabelEx

  • or wait for PHP 5.3 (still have to change Yii though)


found your post a few days ago and thought mmm what is he referring too (there are things that I dont know … ;)

but today I am coming across just this …

trying to call :


in a Base Model class

I would have expected CLASS  (or self) to return the name of the child class

but … no :(

this is a little annoying

Wait for PHP 5.3. ;)