#49625 [Bgs]: spl_autoload and case sensitivity

2009-09-23 Thread sjoerd
 ID:   49625
 Updated by:   sjo...@php.net
 Reported By:  jo at feuersee dot de
 Status:   Bogus
 Bug Type: SPL related
 Operating System: Linux
 PHP Version:  5.3.0
 New Comment:

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.


Previous Comments:


[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 feature/bug of spl_autoload().

As a compromise I propose the following:
1) spl_autoload() additionally tries to find a file _not_ lowercased.
2) Throw a E_DEPRECATED in case the filename had to be lowercased to
match.

Until then:
I really don't know why this lowercasing thing was introduced into
slp_autoload() to begin with, all it ever did was preventing classes to
be named with upper case letters on file systems which are case
sensitive. In other words: the only compatibility issue is that code
which currently works on platforms like Windows only would suddenly work
on UN*X like platforms too.

Pls confirm if this is the compatibility issue you are talking about.



[2009-09-22 16:22:22] sjo...@php.net

Thank you for your bug report.

Wontfix means: we agree that there is a bug, but there are reasons not
to fix it. The reason here is that is spl_autoload becomes case
sensitive, it will break scripts which depend on spl_autoload being case
insensitive.



[2009-09-22 16:01:15] jo at feuersee dot de

Description:

This is basically the same as PHP bug #48129.

Yes, I have read it "won't fix"

My opinion on this is "won't fix" is not an option because it _is_ a
bug and not fixing bugs does not work:

1) It is common practice in OO languages (including PHP) to give
classes case sensitive names. Even the classes of PHP itself are case
sensitive and usually start with capital letters (eg. DateTime,
Exception, ...). PHP related projects like PEAR, Zend Framework etc. do
the same.

2) In order to get a proper 1:1 mapping from class name to the file
containing the PHP class definition, projects like PEAR or Zend
Framework use the case sensitive class name, eg. System.php contains the
class System. Again, this is common practice in other OO languages like
C++.

3) What happens when the file system is case sensitive?
See example: the script fails because the PEAR class System will be
looked for in a file named system.php which does not exist because it is
called System.php
The workaround is using SPL_autoload_suxx instead. But look at the

#49625 [Bgs]: spl_autoload and case sensitivity

2009-09-22 Thread jo at feuersee dot de
 ID:   49625
 User updated by:  jo at feuersee dot de
 Reported By:  jo at feuersee dot de
 Status:   Bogus
 Bug Type: SPL related
 Operating System: Linux
 PHP Version:  5.3.0
 New Comment:

>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 feature/bug of spl_autoload().

As a compromise I propose the following:
1) spl_autoload() additionally tries to find a file _not_ lowercased.
2) Throw a E_DEPRECATED in case the filename had to be lowercased to
match.

Until then:
I really don't know why this lowercasing thing was introduced into
slp_autoload() to begin with, all it ever did was preventing classes to
be named with upper case letters on file systems which are case
sensitive. In other words: the only compatibility issue is that code
which currently works on platforms like Windows only would suddenly work
on UN*X like platforms too.

Pls confirm if this is the compatibility issue you are talking about.


Previous Comments:


[2009-09-22 16:22:22] sjo...@php.net

Thank you for your bug report.

Wontfix means: we agree that there is a bug, but there are reasons not
to fix it. The reason here is that is spl_autoload becomes case
sensitive, it will break scripts which depend on spl_autoload being case
insensitive.



[2009-09-22 16:01:15] jo at feuersee dot de

Description:

This is basically the same as PHP bug #48129.

Yes, I have read it "won't fix"

My opinion on this is "won't fix" is not an option because it _is_ a
bug and not fixing bugs does not work:

1) It is common practice in OO languages (including PHP) to give
classes case sensitive names. Even the classes of PHP itself are case
sensitive and usually start with capital letters (eg. DateTime,
Exception, ...). PHP related projects like PEAR, Zend Framework etc. do
the same.

2) In order to get a proper 1:1 mapping from class name to the file
containing the PHP class definition, projects like PEAR or Zend
Framework use the case sensitive class name, eg. System.php contains the
class System. Again, this is common practice in other OO languages like
C++.

3) What happens when the file system is case sensitive?
See example: the script fails because the PEAR class System will be
looked for in a file named system.php which does not exist because it is
called System.php
The workaround is using SPL_autoload_suxx instead. But look at the
code: there are several compatibility issues (include_path separator :
vs. ;), it does work but is not at all convenient.

4) What would happen if spl_autoload() wouldn't lowercase the class
name when looking for a class definition?
a) Filesystem is case sensitive
It would work!
The spl_autoload() would