Edit report at https://bugs.php.net/bug.php?id=49625&edit=1
ID: 49625
Comment by: blake dot soley at gmail dot com
Reported by:jo at feuersee dot de
Summary:spl_autoload and case sensitivity
Status: Bogus
Type: Bug
Package:SPL related
Operating System: Linux
PHP Version:5.3.0
Block user comment: N
Private report: N
New Comment:
I agree, this bug is not bogus. In fact, it's actually quite serious. Just
because spl_autoload was designed poorly doesn't mean it has to remain broken.
Several fixes have been proposed, please consider implementing one of them to
make this function cross-platform, and therefore useful.
Previous Comments:
[2011-08-10 01:13:40] bram048 at gmail dot com
I agree with Simon. There is absolutely no reason not to fix this, while
keeping
backwards compatibility.
Two years ago the reason for not fixing it was "breaking BC is not an option".
There are plenty of alternatives, and to be honest, PHP has broken BC alot of
times in the last few versions (which is a good thing in my opinion, as long as
the language becomes cleaner/stricter).
Having all the files in lowercase makes them alot harder to read. Having a
custom autoloader function is slower and more complicated to get right, and
just
makes code more ugly and harder to understand.
At the very least case sensitivity of the SPL autoloader should be
configurable,
or available by the use of an extra suffix. I would love to see this in the new
5.4 release; shouldn't take more than a few lines of code.
[2011-03-08 13:08:42] simon at systemparadox dot co dot uk
Why is this bug marked as bogus?
Even if spl_autoload itself isn't fixed, at the very least a version that does
it correctly could be added (although in this case it seriously could just be
fixed by trying the correct case first).
Implementing one in PHP is all very well, but that means that it's non-standard
and likely incompatible with what each programmer might expect. It's also
slower.
[2009-09-23 07:11:47] sjo...@php.net
Trying both lowercased and original case could solve this without breaking
backwards compatibility. However, you could as well supply your own autoload
function defined in PHP to solve this.
[2009-09-22 19:37:20] jo at feuersee dot de
>The reason here is that is spl_autoload becomes case
>sensitive, it will break scripts which depend on spl_autoload being
>case insensitive.
spl_autoload() was introduced in PHP 5.1.2 which is case sensitive concerning
class names. This implies that if an operation on an unknown class is done,
spl_autoload() is triggered and executed with the case sensitive name of the
class.
Thus we have 4 different possibilities:
1) The class name all lower case, the file containing the class definition is
all lower case (eg. $foo = system::bar(); system.php)
This will work independent wether spl_autoload() is lowercasing or not, since
all is lowercased.
Note that if the class defined in the file system.php is actually named System
it wouldn't have ever worked because the class system is still not defined,
which would trigger an error.
2) The class name all lower case, the file containing the class definition is
uppercased (eg. $foo = system::bar(); System.php)
This wouldn't work anymore on file systems which are case sensitive if
spl_autoload() would skip lowercasing.
Note that this would only have worked if the file system is case insensitive
and the class definition in System.php would define a class "system".
3) The class name contains upper case letters, the file containing the class
definition is lowercased (eg. $foo = System::bar(); system.php)
This is what currently isn't working at all but would work at least for case
insensitive file systems if lowercasing would be dropped.
Note that if the class defined in the file system.php is actually named system
it wouldn't have ever worked because the class System is still not defined.
4) The class name contains upper case letters, the file containing the class
definition is uppercased (eg. $foo = System::bar(); System.php)
This is what should (and would) work, but currently doesn't.
Conclusion:
The only problem might be (2):
Class name: sample
Filename: Sample.php
Class definition in Sample.php: class sample { ... }
Note: this does work on case insensitive file systems only.
I really can't see any reason for maintaining the "Worse is better" principle
here, I really doubt that there is much code around relying on the tolowercase