Skip to content

Instantly share code, notes, and snippets.

@gustavnikolaj
Created July 14, 2012 14:20
Show Gist options
  • Save gustavnikolaj/3111563 to your computer and use it in GitHub Desktop.
Save gustavnikolaj/3111563 to your computer and use it in GitHub Desktop.
Alternative PHP Autoloader

Alternative PHP Autoloader

An alternative way of writing an autoload-function. From my personal experience it works and returns the proper boolean values.

Feedback is welcome!

<?php
function traditional_autoload($class)
{
$class = 'path/to/' . $class . '.php';
$file = stream_resolve_include_path($class);
if ($file) { require $file; }
return $file !== false;
}
function alternative_autoload($class) {
return false !== (@include('path/to/' . $class . '.php'));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment