Skip to content

Instantly share code, notes, and snippets.

@tayyebi
Created April 17, 2025 07:27
Show Gist options
  • Save tayyebi/ca340e0d00a17f90b8d019d20a48a701 to your computer and use it in GitHub Desktop.
Save tayyebi/ca340e0d00a17f90b8d019d20a48a701 to your computer and use it in GitHub Desktop.
PHP Auto-loader
<?php
spl_autoload_register(function (string $class_name): void {
$namespace = 'Gordarg';
if (strpos($class_name, $namespace) === 0) {
$class_file = ROOT_PATH . 'src';
$class_file .=
str_replace(
[$namespace, '\\'],
['', DIRECTORY_SEPARATOR],
$class_name
)
. '.php';
if (file_exists($class_file)) {
require_once $class_file;
return;
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment