Bug #51991 [Com]: spl_autoload and *nix support with namespace

From: Date: Sat, 09 Nov 2013 22:54:36 +0000
Subject: Bug #51991 [Com]: spl_autoload and *nix support with namespace
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-182685@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=51991&edit=1 ID: 51991 Comment by: moon at quantentunnel dot de Reported by: grummfy at gmail dot com Summary: spl_autoload and *nix support with namespace Status: Closed Type: Bug Package: SPL related Operating System: linux, mac, *nix PHP Version: 5.3.2 Assigned To: felipe Block user comment: N Private report: N New Comment: After searching around a while I found a workaround without performance loss. 1. Slower but not working with camelcase class files (like "MyClass.php"): spl_autoload_register(function($classname) { require_once(__DIR__ . '/' . str_replace('\\', '/', $classname) . '.php'); }); 2. Faster but not working with camelcase class files: set_include_path(get_include_path() . PATH_SEPARATOR . __DIR__); spl_autoload_extensions(".php"); spl_autoload_register(); spl_autoload_register( function($classname) {} ); 3. Faster and working with camelcase class files: set_include_path(get_include_path() . PATH_SEPARATOR . __DIR__); spl_autoload_extensions(".php"); spl_autoload_register(function ($classname) { spl_autoload($classname); }); Previous Comments: ------------------------------------------------------------------------ [2011-02-23 03:36:04] mike at digitalstruct dot com This is hard to believe that automatically lowercasing the path is not a bug... the majority of PHP users are actually on *nix platforms - especially in production. Causing the paths to automatically be lowercase drastically takes away from the default functionality. I apologize if I am being arrogant here - however, when you write include 'My/Path/To/A/File.php' it does not lowercase that path so why should spl_autoload do anything different with the default behavior? Offending code to fix this is on line: 303 in trunk of php_spl.c: 303 >--- lc_name = zend_str_tolower_dup(class_name, class_name_len); Removing the str_tolower would resolve this issue and we would all be happy. I will post to php-dev as well with a patch. ------------------------------------------------------------------------ [2010-07-28 00:20:23] felipe@php.net Exactly. You can implement your custom autoload to behaves as you want. The lowercased stuff is good for some people, but is not the desired for others. ------------------------------------------------------------------------ [2010-07-27 20:05:46] xstansa at gmail dot com Are you saying that I'll have to rename all my php file names to be lowercase on Linux to use spl_autoload? ------------------------------------------------------------------------ [2010-07-27 03:34:20] felipe@php.net Hi, I forgot to say... the path that will be tried to be found it is lowercased. i.e. my/framework/test.php See bug #52406 Thanks. ------------------------------------------------------------------------ [2010-07-27 02:58:24] xstansa at gmail dot com I've already checked that using phpinfo(). It is PHP 5.3.3. ------------------------------------------------------------------------ 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=51991 -- Edit this bug report at https://bugs.php.net/bug.php?id=51991&edit=1

« previous php.bugs (#182685) next »