# [PATCH] Bug #49852 & Bug #53065 - Adding spl_autoload_case_sensitivity()

- Thread: https://externals.io/message/51134
- Original archive: https://news-web.php.net/php.internals/51134
- Started by Marc Easen on 2010-12-26T13:20:23+00:00
- Messages: 7
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #51134 — Marc Easen — 2010-12-26T13:20:23+00:00

URL: https://externals.io/message/51134#51134

Hello everyone,

Firstly I would like to introduce myself, my name is Marc Easen and I've working with PHP for past 6 years or so. I'm really excited to see where PHP is going with the addition of namespaces and now traits, and hopefully I'm able to contribute back to PHP community.

I've currently working on a high performance PHP Framework based on version 5.3.3+ (5.3.99-dev for traits). Due to the high performance nature of this framework I've been looking at ways of improving the loading of the classes. It seems by default the `spl_autoload()` function lowercases the class name before trying to locate the file, a couples of users have reported this previously and have requested a fix (bug #49852 http://bugs.php.net/bug.php?id=49852 & bug #53065 http://bugs.php.net/bug.php?id=53065). `spl_autoload()` lower casing the class names when it is trying to locate the file does not work on *nix based system in a lot of PHP Frameworks - Zend Framework being on of them.

Understanding the requirement to support backwards compatibility both submitters suggested implementing a spl_autoload_case_sensitivity() function. The patch I have attached adds such a function to the SPL extension. The patch is against trunk (r306670), it also includes phpt tests for this function.

Please could someone review this patch and let me know what you think. 

Kind Regards,

Marc

---

## #51260 — Marc Easen — 2011-01-12T22:53:52+00:00

URL: https://externals.io/message/51134#51260 · In reply to: #51134

Hello again,

Has anyone had a chance to look at my patch?

Forgive me for being quite eager to get this into trunk, as it will improve the performance of all PHP Frameworks which currently implement their own autoloader method due to the oddities of the SPL autoloader.



Kind Regards
Marc




> Hello everyone,
> 
> Firstly I would like to introduce myself, my name is Marc Easen and I've working with PHP for past 6 years or so. I'm really excited to see where PHP is going with the addition of namespaces and now traits, and hopefully I'm able to contribute back to PHP community.
> 
> I've currently working on a high performance PHP Framework based on version 5.3.3+ (5.3.99-dev for traits). Due to the high performance nature of this framework I've been looking at ways of improving the loading of the classes. It seems by default the `spl_autoload()` function lowercases the class name before trying to locate the file, a couples of users have reported this previously and have requested a fix (bug #49852 http://bugs.php.net/bug.php?id=49852 & bug #53065 http://bugs.php.net/bug.php?id=53065). `spl_autoload()` lower casing the class names when it is trying to locate the file does not work on *nix based system in a lot of PHP Frameworks - Zend Framework being on of them.
> 
> Understanding the requirement to support backwards compatibility both submitters suggested implementing a spl_autoload_case_sensitivity() function. The patch I have attached adds such a function to the SPL extension. The patch is against trunk (r306670), it also includes phpt tests for this function.
> 
> Please could someone review this patch and let me know what you think. 
> 
> Kind Regards,
> 
> Marc
> <spl_autoload_case_sensitive.patch

---

## #51261 — ar@ez.no — 2011-01-13T00:04:52+00:00

URL: https://externals.io/message/51134#51261 · In reply to: #51260

Wouldn't it be better to join forces with the SplClassLoader proposal[1]?
A C implementation of PSR-0 has been prpoposed [2] as well, and would be
nice to get something like that into 5.next

However for your imminent performance needs, you should be aware that an
hash map based autoloaders can be fast as well [3].


[1] http://wiki.php.net/rfc/splclassloader
[2] http://blog.runpac.com/post/splclassloader-php-extension-benchmarks
[3]
http://weierophinney.net/matthew/archives/245-Autoloading-Benchmarks.html

Best
ar




> Hello again,
>
> Has anyone had a chance to look at my patch?
>
> Forgive me for being quite eager to get this into trunk, as it will improve
> the performance of all PHP Frameworks which currently implement their own
> autoloader method due to the oddities of the SPL autoloader.
>
>
>
> Kind Regards
> Marc
>
>
> 
>
> Hello everyone,
>
> Firstly I would like to introduce myself, my name is Marc Easen and I've
> working with PHP for past 6 years or so. I'm really excited to see where PHP
> is going with the addition of namespaces and now traits, and hopefully I'm
> able to contribute back to PHP community.
>
> I've currently working on a high performance PHP Framework based on version
> 5.3.3+ (5.3.99-dev for traits). Due to the high performance nature of this
> framework I've been looking at ways of improving the loading of the classes.
> It seems by default the `spl_autoload()` function lowercases the class name
> before trying to locate the file, a couples of users have reported this
> previously and have requested a fix (bug #49852
> http://bugs.php.net/bug.php?id=49852 & bug #53065
> http://bugs.php.net/bug.php?id=53065). `spl_autoload()` lower casing the
> class names when it is trying to locate the file does not work on *nix based
> system in a lot of PHP Frameworks - Zend Framework being on of them.
>
> Understanding the requirement to support backwards compatibility both
> submitters suggested implementing a spl_autoload_case_sensitivity()
> function. The patch I have attached adds such a function to the SPL
> extension. The patch is against trunk (r306670), it also includes phpt tests
> for this function.
>
> Please could someone review this patch and let me know what you think.
>
> Kind Regards,
>
> Marc
> <spl_autoload_case_sensitive.patch

---

## #51504 — Mike Willbanks — 2011-02-23T03:04:47+00:00

URL: https://externals.io/message/51134#51504 · In reply to: #51261

I think it would be better just to fix the issue in the code.  If you
run include 'My/Path/To/File.php' does it lowercase it?  It does not.
The expected behavior would to not lowercase it.  There are ways that
this could be fixed directly in the code.  The only real requirement
that it looks like the need for lowercase is for the hash table that
is internally maintained by spl_autoload for the loading of classes.

To fix this w/o a BC break and give the expected behavior, it could
look for the class first by lowercasing the path and then secondarily
look by the correct case (or the opposite).  The only real usefulness
of the default behavior is for windows users whereas the majority of
installs is on *nix platforms.

The other way (and cleaner IMO) than the current patch if the above
wouldn't work is to add a forth parameter to spl_autoload_register to
tell it to by type sensitive.  The only BC break that is really
possible here is for *nix users that are expecting it to always be
lowercase, however, this seems to be more or less an edge case and
should ultimately just be fixed.  I have not seen one project that
utilizes the spl_autoload default functionality since their class
naming structure generally consists of upper and lowercase letters.

To keep consistency it could certainly be a boolean with the function
declaration of (keeping BC of course):
bool spl_autoload_register ([ callback $autoload_function [, bool
$throw = true [, bool $prepend = false [, bool $case_sensitive = false
]]]] )

I can build a patch for this route if someone would like... I just
think that instead of the SplClassLoader proposal something also needs
to happen with the spl_autoload area as well.

Regards,

Mike

> Wouldn't it be better to join forces with the SplClassLoader proposal[1]?
> A C implementation of PSR-0 has been prpoposed [2] as well, and would be
> nice to get something like that into 5.next
>
> However for your imminent performance needs, you should be aware that an
> hash map based autoloaders can be fast as well [3].
>
>
> [1] http://wiki.php.net/rfc/splclassloader
> [2] http://blog.runpac.com/post/splclassloader-php-extension-benchmarks
> [3]
> http://weierophinney.net/matthew/archives/245-Autoloading-Benchmarks.html
>
> Best
> ar
>
>
> 
>
> > […]

---

## #51648 — Mike Willbanks — 2011-03-09T18:34:18+00:00

URL: https://externals.io/message/51134#51648 · In reply to: #51504

I was just thinking about this again and have a working patch for this.

It seems like the only potential BC break is on linux if people were
using all lowercase paths.  To me it would seem like this is really
not the case or would happen only sometimes.  The quick solution is to
utilize the following patch:

Index: ext/spl/php_spl.c
===================================================================
--- ext/spl/php_spl.c	(revision 306413)
+++ ext/spl/php_spl.c	(working copy)
@@ -229,7 +229,7 @@
 	zval *result = NULL;
 	int ret;

-	class_file_len = spprintf(&class_file, 0, "%s%s", lc_name, file_extension);
+	class_file_len = spprintf(&class_file, 0, "%s%s", class_name, file_extension);

 #if DEFAULT_SLASH != '\\'
 	{


It would seem that this could be addressed for PHP Next with the BC
break (since it is very unlikely to really hit).

Regards,

Mike


> I think it would be better just to fix the issue in the code.  If you
> run include 'My/Path/To/File.php' does it lowercase it?  It does not.
> The expected behavior would to not lowercase it.  There are ways that
> this could be fixed directly in the code.  The only real requirement
> that it looks like the need for lowercase is for the hash table that
> is internally maintained by spl_autoload for the loading of classes.
>
> To fix this w/o a BC break and give the expected behavior, it could
> look for the class first by lowercasing the path and then secondarily
> look by the correct case (or the opposite).  The only real usefulness
> of the default behavior is for windows users whereas the majority of
> installs is on *nix platforms.
>
> The other way (and cleaner IMO) than the current patch if the above
> wouldn't work is to add a forth parameter to spl_autoload_register to
> tell it to by type sensitive.  The only BC break that is really
> possible here is for *nix users that are expecting it to always be
> lowercase, however, this seems to be more or less an edge case and
> should ultimately just be fixed.  I have not seen one project that
> utilizes the spl_autoload default functionality since their class
> naming structure generally consists of upper and lowercase letters.
>
> To keep consistency it could certainly be a boolean with the function
> declaration of (keeping BC of course):
> bool spl_autoload_register ([ callback $autoload_function [, bool
> $throw = true [, bool $prepend = false [, bool $case_sensitive = false
> ]]]] )
>
> I can build a patch for this route if someone would like... I just
> think that instead of the SplClassLoader proposal something also needs
> to happen with the spl_autoload area as well.
>
> Regards,
>
> Mike
>
> > […]

---

## #51649 — Michael Maclean — 2011-03-09T19:06:59+00:00

URL: https://externals.io/message/51134#51649 · In reply to: #51648

> It seems like the only potential BC break is on linux if people were
> using all lowercase paths.  To me it would seem like this is really
> not the case or would happen only sometimes.

I'd have trouble finding a single one of my apps that had a path with 
any uppercase characters at all. They all run on Linux.

-- 
Cheers,
Michael

---

## #51651 — Mike Willbanks — 2011-03-09T19:35:22+00:00

URL: https://externals.io/message/51134#51651 · In reply to: #51649

Do you use lowercase paths and have capitals in your class names?
That is really where this goes into.  Much of PEAR and just about all
of the frameworks are following a specific area.  The main key item
here is that \My\Class is generally in a folder like My/Class.php.
Right now spl_autoload would translate this to look at: my/class.php
by default which one would likely think that it would be My/Class.php
being the one that would be autoloaded since we did not type it
lowercase.

Regards,

Mike

On Wed, Mar 9, 2011 at 1:06 PM, Michael Maclean
<michael@no-surprises.co.uk> wrote:
> 
>
> > […]
>
> I'd have trouble finding a single one of my apps that had a path with any
> uppercase characters at all. They all run on Linux.
>
> --
> Cheers,
> Michael
