Skip to content

Instantly share code, notes, and snippets.

@puiutucutu
Last active December 5, 2022 22:48
Show Gist options
  • Save puiutucutu/8d824953c7f845d3d6ea42227efc3792 to your computer and use it in GitHub Desktop.
Save puiutucutu/8d824953c7f845d3d6ea42227efc3792 to your computer and use it in GitHub Desktop.
PHP spl_autoload_register for linux servers
<?php
// instantiate SPL (Standard PHP Library) Autoloader
spl_autoload_register(function ($class) {
// replace namespace separators with directory separators and append with .php
$file = str_replace('\\', '/', $class . '.php');
if (file_exists($file)) {
require $file;
}
});
<?php
// instantiate SPL (Standard PHP Library) Autoloader
spl_autoload_register(function($class) {
// base directory for the namespace prefix
$baseDirectory = 'C:\Users\AdminUser\Documents\App\' . DIRECTORY_SEPARATOR;
// build file path
$file = $baseDirectory . $class . '.php';
if (file_exists($file)) {
require $file;
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment