Skip to content

Instantly share code, notes, and snippets.

@alganet
Created February 9, 2011 19:33
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alganet/819098 to your computer and use it in GitHub Desktop.
Save alganet/819098 to your computer and use it in GitHub Desktop.
less javaish SplClassLoader
<?php
spl_autoload_register(
function($className) {
$fileParts = explode('\\', ltrim($className, '\\'));
if (false !== strpos(end($fileParts), '_'))
array_splice($fileParts, -1, 1, explode('_', current($fileParts)));
$file = implode(DIRECTORY_SEPARATOR, $fileParts) . '.php';
foreach (explode(PATH_SEPARATOR, get_include_path()) as $path) {
if (file_exists($path = $path . DIRECTORY_SEPARATOR . $file))
return require $path;
}
}
);
@diegoholiveira
Copy link

Excelente exemplo de uso de funções anonimas. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment