Last Updated: February 25, 2016
·
1.335K
· 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';
} );

Have a fresh tip? Share with Coderwall community!

Post
Post a tip
Related Tags
#php
Did you know?

PHP applications still send a browser full of JavaScript. Hardening the server does not inventory the payment, analytics, and plugin scripts that run after the HTML is delivered.

Security insights from Cside