dslreports logo
site
 
    All Forums Hot Topics Gallery
spc

spacer




how-to block ads


Search Topic:
uniqs
579
share rss forum feed


PToN
Premium
join:2001-10-04
Houston, TX

PHP autoloading and SPL classes

Hello,

I have a very basic auto load function:

function LoadClass( $className )
{
    $className = ltrim($className, '\\');
    $fileName  = '';
    $namespace = '';
    
    if ($lastNsPos = strripos($className, '\\')) 
    {
        $namespace = substr($className, 0, $lastNsPos);
        $className = substr($className, $lastNsPos + 1);
        $fileName  = str_replace('\\', DIRECTORY_SEPARATOR, $namespace) . DIRECTORY_SEPARATOR;
    }
    
    $fileName .= str_replace('_', DIRECTORY_SEPARATOR, $className) . '.php';
 
    if (is_file(LIBPATH.$fileName))
            require LIBPATH.$fileName;
    else
        require APPSPATH.$fileName;
    
}
 
spl_autoload_register( 'LoadClass' );
 

Everything works fine, except the SPL classes. If i try to do something like:
throw new Exception(....)
 

It tries to find the Exception class in the paths i specified, but never loads the SPL class.

Any ideas??

Thanks.