Why do Yii system files not have ?> at end?


I’ve installed yii and it looks really great. I’ve had experience with Cake, Zend, Rails and CodeIgniter and Yii seems relatively easy to get on its feet.

One problem I had though is setting up the documentations’ testdrive. At first when I run it, apache shuts down (I’m well familiar with that). I went rummaging the yii code for some clues, and I saw no trailing ?> at the end of index.php.

Fixed it.

Then reloaded testdrive/index.php, apache does NOT shut down, but instead I get a fatal error that some class doesn’t exist. That file didn’t have a trailing ?> at the end either. Fixed it.

Reloaded index.php, now different class doesn’t exist:

Class ‘CComponent’ not found in C:\htdocs\yii\framework\base\CModule.php on line 21

This is definitely a symptom of the lack of ?> at the end of php docs. Have y’all found any at your documents? Why does that lack in my installation of Yii (I downloaded it today, have PHP 5.2).

I appreciate the advice.

Not using of ?> is intentional. Good description is in ZF’s guide: http://framework.zend.com/manual/en/coding-standard.php-file-formatting.html

This page is worth reading too:


It explains how PHP interprets code between the <?php and ?> tags, and why it is necessary for it to output anything that follows the closing tag.

Having said that, I’ve always closed the opening tags, as I don’t find it difficult to ensure that there are no unwanted characters following the closing tag. I would feel almost dirty not closing them… :)

I understand this is unconventional, that’s why I initially asked why my installation of yii did not consist of closing tags on any of the files?

Is your installation similar? My server seems to not be able to interpret php without the closing tag and I’m not in the mood for editing all files of yii to include them lol.

This is intentional and it’s a good code standard set up by Zend. All installations are similar: there are no closing tags in Yii.

I have not heard of any problems with not including closing tags before. Should be very specific to your server.

I’ve never came across this and normally it should work without problems. Do you use any php opcode caching? Maybe you can also try to upgrade your php version. Maybe there’s a compiler option that forces you to close the tags, I don’t know.

Ok, so I suppose it’s a problem with my apache or php installations. Thank you all for the responses, I’m gonna try to upgrade php and see where it goes from there.

I’d be interested to know what you find - I’ve had no problem with the downloaded code. I’ve Googled, and found nothing. It might be worth checking your Apache logs, and perhaps increasing the logging level.

Hi guys,

Revisiting my issue, it seems the problem really was with apache. I looked into the extensive error logs and something in my opinion pointed at apache not finding the local server name. When I provided it the right address 291… something and the right port (:0) I totally stopped working --> problem.

I updated apache and now it’s working fine (I got the Congratulations! You have successfully created your Yii application.)

Thanks a lot for the help, Yii seems to have a genuinely great community around it.