Edit report at https://bugs.php.net/bug.php?id=49625&edit=1
ID: 49625
Comment by: bart at mediawave dot nl
Reported by: jo at feuersee dot de
Summary: spl_autoload and case sensitivity
Status: Not a bug
Type: Bug
Package: SPL related
Operating System: Linux
PHP Version: 5.3.0
Block user comment: N
Private report: N
New Comment:
Or add some option like:
spl_autoload_register(null, null, null, true);
to autoload files in a case sensitive manner.
The power of PHP comes by leveraging the C implementation of things. This should be possible
natively in combination with an elegant project folder/class name structure.
Previous Comments:
------------------------------------------------------------------------
[2014-09-13 10:53:59] xxmlltwer at yahoo dot de
Why you just don't make two functions or a flag which tells php if it should do it's job
case sensitive or case insensitive?
That can't be too hard!
------------------------------------------------------------------------
[2014-07-02 12:14:27] simon at systemparadox dot co dot uk
The correct answer of course being solution 2: enforce case sensitivity on all class names (and
functions too, whilst we are on the subject), like any sane language.
This is not hard to fix. Add a deprecation warning for anyone who uses a class name that
doesn't exactly match the case it was defined in, then at some point in the future change the
functionality. Anyone who didn't pay attention to the deprecation warnings, or worse,
didn't have warnings enabled, deserves everything they get.
This is a long slow process to fix, which should have been started years ago.
------------------------------------------------------------------------
[2014-07-02 10:42:57] tom at r dot je
One thing everyone here seems to be missing here is that php classes are not case sensitive:
This code will execute correctly:
class FooBar {
}
new foobar;
new FooBar;
new FOOBAR;
new fooBar;
However, add autoloading into the mix and you create action at a distance that isn't
immediately obvious:
if the class is in FooBar.php and you have a case-sensitive autoloader then this executes:
new FooBar;
new foobar;
but this does not:
new foobar;
new FooBar;
Should the order of operations here have any affect on whether this script runs successfully or not?
Even worse, lets say you have:
function a() {
new FooBar;
}
function b(){
new foobar;
}
function c() {
a();
b();
}
What's even less obvious is that if the implementation of the a function changes to no longer
need the FooBar class, the c function stops working. To the developer working on the a function, the
implementation has changed but the API has not so should have no negative effect on anything
external, yet another part of the application now breaks for no obvious reason.
The PHP Developers are correct that this is not a bug and it's more sensible for the autoloader
to be case insensitive. One of two things need to happen:
1) All autoloaders should be case-insensitive
OR
2) PHP enforces case sensitivity on all class names.
------------------------------------------------------------------------
[2014-06-24 15:08:34] me at mhlz dot de
I just spent 2 hours to get the naming conventions inline with all the other OOP languages out there
(meaning CamelCase filenames) only to find out that spl_autload is broken.
This needs to be fixed. It is completely unexpected behaviour (if it tries to load "Class"
it should be able to locate "Class.php". If backwards compatibility is such a big problem,
then please add some kind of flag for it. It's ridiculous that you have to work around this
"feature".
------------------------------------------------------------------------
[2013-11-09 23:36:38] moon at quantentunnel dot de
I'm sorry, my last post was not correct, case 3 does not work :-(
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
https://bugs.php.net/bug.php?id=49625
--
Edit this bug report at https://bugs.php.net/bug.php?id=49625&edit=1