registerScript() position not working

I am trying to create a global Javascript variable using the CClientScript method registerScript(). The problem is that the global variable is being inserted at the bottom of the page instead of the head.

$cs = Yii::app()->getClientScript();


$js = "var my_global = 'some text';";

$cs->registerScript('myextension_'.$this->getId(), $js, CClientScript::POS_HEAD);

Why is the script going at the bottom instead of the head?

Nevermind. I did more debugging and found out I was calling the registerScript method from two locations. :confused: