[dev] Fwd: include vs include_once in Horde_Autoloader

Michael M Slusarz slusarz at horde.org
Tue Aug 4 23:32:52 UTC 2009


Quoting Michael Rubinsky <mrubinsk at horde.org>:

> Quoting Michael M Slusarz <slusarz at horde.org>:
>
>> Quoting Michael Rubinsky <mrubinsk at horde.org>:
>>
>>>> Horde_Autoloader::addClassPattern('/^' . $app . '[$_]/i', $app_lib);
>>>
>>> This results in the application's base class not being loadable.  
>>> i.e. Kronolith::
>>
>> Why not?  Oh, square brackets only match characters, not special  
>> pattern.  D'oh.  This should be correct:
>>
>> Horde_Autoloader::addClassPattern('/^' . $app . '(?:$|_)/i', $app_lib);
>>
>> Sure enough, it works:
>>
>> preg_match('/^kronolith(?:$|_)/i', 'Kronolith_Test', $matches);
>> print_r($matches);
>> Array
>> (
>>    [0] => Kronolith_
>> )
>>
>>
>> preg_match('/^kronolith(?:$|_)/i', 'Kronolith', $matches);
>> print_r($matches);
>> Array
>> (
>>    [0] => Kronolith
>> )
>
> Nope. Still broken. The issue is that kronolith/lib is never put on  
> the include path if the addClassPath() call is removed. If it's left  
> in, then the original problem still exists.

II think the issue is that we should avoid using addClassPath() for  
applications.  Instead, we should directly include files in  
applications only if it matches a string from addClassPattern().  If  
the classname doesn't match any class pattern, only then do a final  
include that tries to load from any of the directories in include_path.

I've uploaded changes to an 'autoload' branch in horde-git.  Try  
pulling that commit and see if it works for you.  Unfortunately, you  
will probably also have to make this change manually in  
horde/lib/core.php:

-Horde_Autoloader::addClassPattern('/^Horde_/i', $horde_dir);
+Horde_Autoloader::addClassPattern('/^Horde(?:$|_)/i', $horde_dir);

(We really need to get base horde stuff in Git - it would make these  
kind of changes much easier to test and/or rollback.)

michael

-- 
___________________________________
Michael Slusarz [slusarz at horde.org]



More information about the dev mailing list