Possible bug in autoloader

From: Date: Tue, 16 Mar 2010 12:48:37 +0000
Subject: Possible bug in autoloader
Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-53332@lists.php.net to get a copy of this message
I was playing around with the pear2 sandbox when I came across a possible bug in the autoloader. The autoloader works by examining the class name required, checking to see if it is within the pear2 namespace, determining several possible filenames that are expected to define that class, checking for their existence, and then including them. For instance (when using the sandbox) if you try to use class pear2\Templates\IT\Template, the file PHPDIR\pear2\sandbox\Templates_IT\trunk\src\Templates\IT\Templates.php is included for the definition of that class. This possible bug arises when the wrong casing is used when trying to use a class. On filesystems that are case sensitive, the filename is not determined correctly. In my case, I went "use PEAR2\Templates\IT\Template;". After some investigation, I discovered that the autoloader was ignoring my "request for definition" because I was using PEAR2 and not pear2. More closely examining the behaviour I discovered that it was easy to cause the autoloader to fail by mixing the case inside the use definitions. On windows, where the casing is ignored this is not a problem, but on other systems, this could present problems. This might be trivial, however, it is highly unexpected behavior as class/namespace names are case-insensitive in PHP. I do consider this a bug because when using classes for the first time, the casing must be exactly as it appears in filesystem (but not subsequent times). I can see quite a few end users using PEAR2 instead of pear2 thinking it doesn't matter. (Side issue: I think "PEAR2" looks sexier). I can also see few developers being aware of the special autoload requirements when using PEAR packages. Any comments?

« previous php.pear.dev (#53332) next »