__sh*tload to the rescue!

How do you think the PureMVC guy tests this autoload function?

/**
* Checks all paths defined in $_includePaths for
* the existence of $class and loads $class if found.
*
* @param string $class The class to search for.
*/
function __autoload( $class )
{
    $_includePaths = array(
                       PMVC_BASE_DIR . '/org/puremvc/php/core',
                       PMVC_BASE_DIR . '/org/puremvc/php/interfaces',
                       PMVC_BASE_DIR . '/org/puremvc/php/patterns',
                       PMVC_BASE_DIR . '/org/puremvc/php/patterns/command',
                       PMVC_BASE_DIR . '/org/puremvc/php/patterns/facade',
                       PMVC_BASE_DIR . '/org/puremvc/php/patterns/mediator',
                       PMVC_BASE_DIR . '/org/puremvc/php/patterns/observer',
                       PMVC_BASE_DIR . '/org/puremvc/php/patterns/proxy',
     );

    $classPath = get_include_path();
    $classPathTokens = explode( ':', $classPath );

    $classXtn = '.php';

    foreach ($classPathTokens as $prefix)
    {
        foreach ($_includePaths as $includePath)
        {
             $path = "$includePath/$class$classXtn";
             if (file_exists($path))
             {
                require_once $path;
                return;
             }
       }
   }

}

Taken from: http://svn.puremvc.org/PureMVC_PHP/tags/1.0.2/puremvc_autoloader.php

Dude, did you know that your get_include_path() is not used at all in this autoload function?

But here, I unit tested it for you

autoload unit test

If you don’t get this joke see here

Advertisement

5 Responses to “__sh*tload to the rescue!”

  1. __sh*tload to the rescue! « baaaaaad php usage exposed Says:

    [...] more here:  __sh*tload to the rescue! « baaaaaad php usage exposed [...]

  2. __sh*tload to the rescue! « baaaaaad php usage exposed | Webmaster Tools Says:

    [...] Here is the original: __sh*tload to the rescue! « baaaaaad php usage exposed [...]

  3. seaofarrows Says:

    Rather than post on your blog, it might be a good idea to post this on the PureMVC PHP forum.

    -=Cliff>

  4. seaofarrows Says:

    http://forums.puremvc.org/index.php?board=17.0

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s


Follow

Get every new post delivered to your Inbox.