1<?php 2 3/** 4 * @see https://github.com/php-fig/fig-standards/blob/a1a0674a742c9d07c5dd450209fb33b115ee7b40/accepted/PSR-4-autoloader-examples.md#closure-example 5 */ 6spl_autoload_register(static function (string $class): void { 7 $prefix = 'phpweb\\'; 8 $directory = __DIR__ . '/'; 9 10 $length = strlen($prefix); 11 12 if (strncmp($prefix, $class, $length) !== 0) { 13 return; 14 } 15 16 $relativeClass = substr( 17 $class, 18 $length, 19 ); 20 21 $file = $directory . str_replace('\\', '/', $relativeClass) . '.php'; 22 23 if (!file_exists($file)) { 24 return; 25 } 26 27 require $file; 28}); 29