Created
January 11, 2012 01:57
-
-
Save robap/1592498 to your computer and use it in GitHub Desktop.
Using psr-0 compliant autoloader
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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