Last Updated: February 25, 2016
·
1.183K
· mtthlm

Simple PHP PSR-0 Autoload

Here's a simple PHP PSR-0 autoload example:

<?php
// autoload.php

spl_autoload_register( function ( $class )
{
    include dirname( __DIR__ ) . DIRECTORY_SEPARATOR . implode( DIRECTORY_SEPARATOR , array_slice( explode( '\\' , $class ) , 0 , -1 ) ) . DIRECTORY_SEPARATOR . str_replace( '_' , DIRECTORY_SEPARATOR , implode( '' , array_slice( explode( '\\' , $class ) , -1 , 1 ) ) ) . '.php';
} );