Skip to content

Instantly share code, notes, and snippets.

@robap
Created January 11, 2012 01:57
Show Gist options
  • Save robap/1592498 to your computer and use it in GitHub Desktop.
Save robap/1592498 to your computer and use it in GitHub Desktop.
Using psr-0 compliant autoloader
<?php
//File: test.php
//Create the file SplClassLoader.php and add the contents of this gist https://gist.github.com/221634
//Example:
//Class Foo\Bar located in 'src/Foo/Bar.php'
require 'SplClassLoader.php';
$autoloader = new SplClassLoader('Foo', 'src');
$autoloader->register();
use Foo\Bar;
$bar = new Bar();
//For php versions prior to 5.3 and using pseudo namespaces:
$autoloader2 = new SplClassLoader('Foo', 'lib');
$autoloader2->setNamespaceSeparator('_');
$autoloader2->register();
$bar = new Foo_Bar();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment