Re: __autoLoad php5 callback is being triggered for every class ?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



* php@xxxxxxxxxxxxxxxx <php@xxxxxxxxxxxxxxxx>:
> I'm experiencing some issues with autoLoad with pear packages. DB_Error is
> contained within the DB.php, but my autoload method is trying to split the
> underscores with forward slashes and then load. Supressing errors with @
> still doesnt work, its triggering a php error. Any ideas ?

Sounds to me like you may need to do a quick call to file_exists()
before trying to load it up. This may involve looping through the
elements in your include_path to build the paths:

    // assuming $class = class requested
    $file = str_replace('_', '/', $class) . '.php';
    $include_path = ini_get('include_path');
    $paths = explode(':', $include_path);
    $final = '';
    foreach ($paths as $path) {
        if (file_exists("$path/$file")) {
            $final = "$path/$file";
            break;
        }
    }
    if (!empty($final)) {
        include_once $final;
    }

-- 
Matthew Weier O'Phinney           | WEBSITES:
Webmaster and IT Specialist       | http://www.garden.org
National Gardening Association    | http://www.kidsgardening.com
802-863-5251 x156                 | http://nationalgardenmonth.org
mailto:matthew@xxxxxxxxxx         | http://vermontbotanical.org

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux