Skip to content

Instantly share code, notes, and snippets.

@shgysk8zer0
Last active August 29, 2015 14:22
Show Gist options
  • Save shgysk8zer0/47fdf867459541e57c27 to your computer and use it in GitHub Desktop.
Save shgysk8zer0/47fdf867459541e57c27 to your computer and use it in GitHub Desktop.
PHP SPL Autoloader
# Configure PHP's autoloader and set include_path
<IfModule env_module>
SetEnv AUTOLOAD_DIR classes
SetEnv AUTOLOAD_EXTS .php
SetEnv AUTOLOAD_FUNC spl_autoload
</IfModule>
# Loads the autoloader script before executing main PHP file
php_value auto_prepend_file ./autoloader.php
<?php
set_include_path(
realpath(getenv('AUTOLOAD_DIR')) .
PATH_SEPARATOR . get_include_path()
);
spl_autoload_extensions(getenv('AUTOLOAD_EXTS'));
spl_autoload_register(getenv('AUTOLOAD_FUNC'));
@shgysk8zer0
Copy link
Author

PHP Autoloader using .htaccess

  • .htaccess file sets environment variables and prepends autoloader script
  • autoloader.php sets include_path and autoloader using getenv

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