note 115369 deleted from language.oop5.autoload by crell
| From: | crell@php.net | Date: | Mon, 04 Apr 2022 16:09:33 +0000 |
| Subject: | note 115369 deleted from language.oop5.autoload by crell | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-218026@lists.php.net to get a copy of this message | ||
Note Submitter: oliver dot strevel at gmail dot com
----
My autoloader function:
<?php
/**
* Funcion de autocarga de clases para php
* Se realiza la busqueda directamente sobre la raiz de la carpeta lib con el prefijo
'.class.php'
*/
function __autoload( $class_name )
{
$invalidChars = array(
'.', '\\', '/', ':', '*', '?',
'"', '<', '>', "'", '|'
);
$class_name = str_replace($invalidChars, '', $class_name);
$extension_prefix = '.class.php';
if( !@include_once $class_name . $extension_prefix )
{
$path = 'lib'; // In this dir the function will search
foreach( new DirectoryIterator($path) as $file )
{
if($file->isDot()) { continue; }
if($file->isDir())
{
$file = $path . DIRECTORY_SEPARATOR . $file->getFilename() . DIRECTORY_SEPARATOR .
$class_name . $extension_prefix;
if(file_exists($file)) {
include_once $file;
}
}
}
}
if (!class_exists($class_name, false) || !interface_exists($class_name, false)) {
// return || Some tracking error task..
}
}
?>