Yii Echoing Extra Whitespace Into Templates?

Yii appears to be echoing out a single space character when I reference a model class for the first time, directly or indirectly. In most cases this doesn’t matter (HTML is pretty liberal about whitespace), but in some cases it’s sticking extra whitespace in the middle of some text, causing generated image files to error out, etc. Here’s an anonymized version of one instance that’s causing us trouble:

<li>My List ({$list->getItemCount()})</li>

(It’s been awhile since I went down this particular rabbit hole but IIRC, calling getItemCount will result in the static model function getting called at some point.)

By itself, the result ends up looking like this:

  • My List ( 4)

After some slogging through the code, I couldn’t find exactly where the space was being output, but I managed to find a pretty bewildering “fix”:

{if User::model() && ListItem::model()}{/if}


<li>My List ({$list->getItemCount()})</li>

This shoves the whitespace in some part of the HTML I don’t really care about, although it’s not exactly pretty. However, there’s no way to do this when outputting an image file, aside from even more gross hacks (redirect output when calling the model?) or avoiding the model() function entirely.

There’s nothing in the User or ListItem model() functions that would cause this. They’re both still in their Gii-generated form, where they return parent::model($className). I also tried removing the PHP closing tags, although there was no whitespace after them anyway. I looked around for a solution, but all I found was another user with a similar-seeming unresolved problem: http://www.yiiframework.com/forum/index.php/topic/42725-cmenu-newline-after-closing-tag/

Am I missing something here? I’m using Yii 1.1 if that makes a difference.

Never mind, I am an idiot. ::) To any future Googlers having this problem, don’t forget to check for whitespace before the opening PHP tags of the model, too.