Skip to content

Instantly share code, notes, and snippets.

@golgote
Forked from adriengibrat/l.php
Created December 22, 2013 20:52
Show Gist options
  • Save golgote/8088288 to your computer and use it in GitHub Desktop.
Save golgote/8088288 to your computer and use it in GitHub Desktop.
<?php
//set_include_path(get_include_path() . PATH_SEPARATOR . __DIR__); // optional
spl_autoload_register(function ($class) {
$file = preg_replace('#\\\|_(?!.+\\\)#','/', $class) . '.php';
if (stream_resolve_include_path($file))
require $file;
});
@golgote
Copy link
Author

golgote commented Dec 22, 2013

<?php
spl_autoload_register(function($class) {
    $parts = explode('\\', $class);

    # Support for non-namespaced classes.
    $parts[] = str_replace('_', DIRECTORY_SEPARATOR, array_pop($parts));

    $path = implode(DIRECTORY_SEPARATOR, $parts);

    $file = stream_resolve_include_path($path.'.php');
    if($file !== false) {
        require $file;
    }
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment