Late Static Bindings


I would like to suggest Yii to use late static bindings for its static classes.

The reason for this is that I recently wanted to customize things in CHtml, clientChange() to be precise. Now what happens is that I define a class Html that inherits CHtml, and then redefined clientChange(). However, when I now call for example Html::button(), then it will not use this new Html::clientChange() as it is called using self::clientChange(), which, contrary to what would make sense, will call CHtml::clientChange(). I can fix this by including every single function that might ever call clientChange() in Html, which of course is an ugly workaround.

The correct way to fix this would be to use PHP 5.3’s late static binding, see here.

This would mean that all references of the form self::something() should be replaced by static::something(). Of course Yii should probably remain compatible with PHP 5.2, so this should be handled according to the PHP version.


Lupin Sansei

Will be in Yii2 if we will still use static classes.