Last active
December 5, 2022 22:48
-
-
Save puiutucutu/8d824953c7f845d3d6ea42227efc3792 to your computer and use it in GitHub Desktop.
PHP spl_autoload_register for linux servers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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; | |
} | |
}); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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