From:             jo at feuersee dot de
Operating system: Linux
PHP version:      5.3.0
PHP Bug Type:     SPL related
Bug description:  spl_autoload and case sensitivity

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 look for a file called System.php which exists,
thus will be require'd

b) Filesystem is not case sensitive
It would still work!
The spl_autoload() would look for a file called System.php
Because the file system is case insensitive, it would use either
System.php or system.php (or sYSTEM.PHP - you got the point?).
Because on case insentive filesystems both files "System.php" and
"system.php" are not allowed in the same directory, there is _no_ issue
with backward compatibility.

The only circumstances where it would break backwards compatibility would
be on filesystem which is case insensitive but does not allow capital
letters. Any real live examples of such a file system? 

Conclusion:
The current specification of spl_autoload() with implicit lowercasing is
excactly wrong. There has been, is and never will be any gain in this
'feature' since the class name itself inside PHP is case sensitive.


Reproduce code:
---------------
<?php
/**
 * Demonstration of the current incompatibility 
 * Make sure you have PEAR inside your PHP include_path
 */

// this should work but doesn't
spl_autoload_register('spl_autoload');

// this does work
//spl_autoload_register('SPL_autoload_suxx');

/**
 * Does the same as spl_autoload, but without lowercasing
 */
function SPL_autoload_suxx($name)
{
        $rc = FALSE;
        
        $exts = explode(',', spl_autoload_extensions());
        $sep = (substr(PHP_OS, 0, 3) == 'Win') ? ';' : ':';
        $paths = explode($sep, ini_get('include_path'));
        foreach($paths as $path) {
                foreach($exts as $ext) {
                        $file = $path . DIRECTORY_SEPARATOR . $name . $ext;
                        if(is_readable($file)) {
                                require_once $file;
                                $rc = $file;
                                break;
                        }
                }
        }
        
        return $rc;
}

$binaries = array(
        'mysql' => System::which('mysql'),
        'mysqlbinlog' => System::which('mysqlbinlog'),
        'php' => System::which('php')
);
print_r($binaries);
                
?>

Expected result:
----------------
Array
(
    [mysql] => /usr/bin/mysql
    [mysqlbinlog] => /usr/bin/mysqlbinlog
    [php] => /usr/local/bin/php
)


Actual result:
--------------
PHP Fatal error:  Class 'System' not found in
/srv/www/vhosts/www.easy-sew.de/ftpjung/bin/autoload.php on line 38


-- 
Edit bug report at http://bugs.php.net/?id=49625&edit=1
-- 
Try a snapshot (PHP 5.2):            
http://bugs.php.net/fix.php?id=49625&r=trysnapshot52
Try a snapshot (PHP 5.3):            
http://bugs.php.net/fix.php?id=49625&r=trysnapshot53
Try a snapshot (PHP 6.0):            
http://bugs.php.net/fix.php?id=49625&r=trysnapshot60
Fixed in SVN:                        
http://bugs.php.net/fix.php?id=49625&r=fixed
Fixed in SVN and need be documented: 
http://bugs.php.net/fix.php?id=49625&r=needdocs
Fixed in release:                    
http://bugs.php.net/fix.php?id=49625&r=alreadyfixed
Need backtrace:                      
http://bugs.php.net/fix.php?id=49625&r=needtrace
Need Reproduce Script:               
http://bugs.php.net/fix.php?id=49625&r=needscript
Try newer version:                   
http://bugs.php.net/fix.php?id=49625&r=oldversion
Not developer issue:                 
http://bugs.php.net/fix.php?id=49625&r=support
Expected behavior:                   
http://bugs.php.net/fix.php?id=49625&r=notwrong
Not enough info:                     
http://bugs.php.net/fix.php?id=49625&r=notenoughinfo
Submitted twice:                     
http://bugs.php.net/fix.php?id=49625&r=submittedtwice
register_globals:                    
http://bugs.php.net/fix.php?id=49625&r=globals
PHP 4 support discontinued:          http://bugs.php.net/fix.php?id=49625&r=php4
Daylight Savings:                    http://bugs.php.net/fix.php?id=49625&r=dst
IIS Stability:                       
http://bugs.php.net/fix.php?id=49625&r=isapi
Install GNU Sed:                     
http://bugs.php.net/fix.php?id=49625&r=gnused
Floating point limitations:          
http://bugs.php.net/fix.php?id=49625&r=float
No Zend Extensions:                  
http://bugs.php.net/fix.php?id=49625&r=nozend
MySQL Configuration Error:           
http://bugs.php.net/fix.php?id=49625&r=mysqlcfg

Reply via email to