Re: Possible bug in autoloader
| From: | Brett Bieber | Date: | Tue, 16 Mar 2010 16:56:53 +0000 |
| Subject: | Re: Possible bug in autoloader | ||
| References: | 1 | Groups: | php.pear.dev |
| Request: | Send a blank email to pear-dev+get-53334@lists.php.net to get a copy of this message | ||
On Tue, Mar 16, 2010 at 7:47 AM, Gregory Currie
<gregory.currie@gmail.com> wrote:
> 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?
Sounds like a good issue to bring up.
Developers for PEAR2 need to know that their code should be autoload
compliant, and therefore should use proper case at every instance
because the autoloader does not modify the case of the namespace or
class name before attempting autoload.
End-users can do as they wish, but if they expect autoloading to work
they need to use the proper case. This should be fairly easy to detect
as the first time they use a class name incorrectly they'll get a
fatal error.
As for pear2 vs PEAR2, the group approved using PEAR2 as the namespace
in the meeting dated 2009-12-20 — the conversion just needs to be
done.
--
Brett Bieber