How to overwrite methods in CWebApplication?

How to overwrite methods in CWebApplication, say, afterControllerAction()? I guess there is “new CWebApplication()” somewhere in the framework, so if I define a class inherit from CWebApplication, it won’t take effect.

Call Yii::createApplication() instead of Yii::createWebApplication() in your entry script, with the name of the extended class as its first parameter.