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 am having some issues initializing SPL classes while using my own framework and autoloader.

Here is my autoloder:

namespace MYFW\Core;
 
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( 'MYFW\Core\LoadClass' );
 

As you can see is very generic and simple, but every time i try to initialize a SPL class (EX: throw new Exception ) my app complaints the class cannot be found.

As per the spl_autoload_register docs, it says it is supposed to append my classes to the SPL list.

Did i miss something?

Thanks.