This issue has originally been reported by @kanyuga at yiisoft/yii2#6689.
Moved here by @cebe.
The init function of the \yii\bootstrap\NavBar class has several lines of code that output html. Since every widget class should contain a call to parent::init(), this class cannot be easily extended since the html in the init function will also sent to the output. I encountered this problem while trying to extend the NavBar class to remove the div that wraps the individual menus.
A proposed solution is to move the bulk of the code in the init function into a separate function.