Last active
November 23, 2021 07:21
-
-
Save macghriogair/efbce404b8e0cac6c724 to your computer and use it in GitHub Desktop.
basic autoload for php 5.2
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 | |
/** | |
* A basic autoload implementation that should be compatible with PHP 5.2. | |
* | |
* @author pmg | |
*/ | |
global $autoLoadFolders; | |
$srcPath = realpath(dirname(__FILE__)) . DIRECTORY_SEPARATOR . 'src'; | |
$scannedItems = scandir($srcPath); | |
foreach ($scannedItems as $item) { | |
if ($item === '.' || $item === '..') { | |
continue; | |
} | |
if (is_dir($folder = $srcPath . DIRECTORY_SEPARATOR . $item)) { | |
$autoLoadFolders[] = $folder; | |
} | |
} | |
function legacyAutoload($className) | |
{ | |
global $autoLoadFolders; | |
foreach ($autoLoadFolders as $folder) { | |
$classPath = $folder. DIRECTORY_SEPARATOR . $className . '.php'; | |
if (file_exists($classPath)) { | |
require_once $classPath; | |
return true; | |
} | |
} | |
return false; | |
} | |
spl_autoload_register('legacyAutoload', true/*, true*/); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment