yii: Inconsistent case sensitivity in Yii autoloader

Say I want to use use a widget in a view thus:

<?php
$this->widget('MyWidget');

And the definition is quite conventional:

<?php
class MyWidget extends CWidget {
…
}

If I save that class in a file called Mywidget.php then the widget works if it is on NTFS, FAT32 or (normal) HFS+.

Now I deploy on FreeBSD or Lunix or something with a case sensitive(CS) FS and my application is broken.

I regard this as a bug because the inconsistent case sensitivity is (I have observed hanging out on Freenode#yii) often not expected by the user and it is not documented in the Yii Class Ref. or Def. Guide.

It is not expected by the user because 1) spl_autoload is case insensitive (CI) regardless of FS and users bring that experience to Yii; 2) the new Yii user’s experience developing on Windows or Mac is of a consistently CI autoloader throughout her learning, application development phase and quite possibly during test too. Deployment is not the best time to learn this crucial lesson.

After the second time I fell foul to this, I spent some time studying Yii’s autoloader and decided that I cannot easily make a fix or workaround for myself. The least bad solution for me was to set up a partition or disk image with a CS FS and put my Yii projects on that.

So: Should Yii simply expect users to use a CS FS in dev or find some other SQA process to eliminate such case typos? If yes, how do they learn that they need to? If no, a change in Yii is needed.

Explaining the behavior in documentation would be good not it is not sufficient—it just turns a bug into a really bad feature.

I don’t know what to suggest for Yii’s autoloader. I think it would be good for Yii and its users if its default autoloader were either CI or CS regardless of FS. But I don’t know if that would be a breaking change for existing Yii apps or if it would have some other unacceptable consequences.

Alternatively, Yii could perhaps be configured to throw a carefully worded exception in a CI environment upon detecting a case mismatch. If this were the default when YII_DEBUG is true, that would help users learn that they need to find some way to ensure that case mismatches are not present in their code.

About this issue

  • Original URL
  • State: closed
  • Created 12 years ago
  • Comments: 53 (45 by maintainers)

Commits related to this issue

Most upvoted comments

For future people: https://plugins.jetbrains.com/plugin/7622-php-inspections-ea-extended-, the plugin has “Class autoloading correctness” inspection for related issues.