/hphp/system/php/spl/miscellaneous/autoload.php
PHP | 27 lines | 19 code | 1 blank | 7 comment | 1 complexity | aa63fd4798d2713276526216993282a8 MD5 | raw file
Possible License(s): LGPL-2.1, BSD-2-Clause, BSD-3-Clause, MPL-2.0-no-copyleft-exception, MIT, LGPL-2.0, Apache-2.0
- <?php
- /**
- * This function is intended to be used as a default implementation for
- * __autoload(). If nothing else is specified and spl_autoload_register()
- * is called without any parameters then this functions will be used for
- * any later call to __autoload().
- */
- function spl_autoload(string $class, ?string $extensions = null) {
- if ($extensions === null) {
- $extensions = spl_autoload_extensions();
- }
- $extensions = explode(',', $extensions);
- // Lowercase, convert namespace separators to path separators
- $normalized = str_replace(
- '\\',
- '/',
- strtolower($class),
- );
- foreach ($extensions as $ext) {
- $filename = $normalized.$ext;
- @include($filename);
- if (class_exists($class)) {
- return;
- }
- }
- }