[PHP-NOTES] note 130317 added to function.autoload

[email protected] ("Anonymous")
Newsgroups php.notes
Message-ID <[email protected]>
class Autocarga {

    public static function registra_autocarga() {
        try {
            spl_autoload_register(self::class . "::autocarga");
        }
        catch(Exception $e) {
            echo "La definición de la clase no se ha encontrado";
            exit(1);
        }
    }

    public static function autocarga($clase): void {
        $directorios = ['periodoRecuperacion\\ra5\\'];

        $clase = str_replace("\\", "/", $clase);
        $encontrado = False;

        foreach($directorios as $directorio ) {
            if( file_exists("{$_SERVER['DOCUMENT_ROOT']}/$directorio/$clase.php") ) {
                require_once("{$_SERVER['DOCUMENT_ROOT']}/$directorio/$clase.php");
                $encontrado = True;
                break;
            }
        }
        if( !$encontrado ) throw new Exception("La clase $clase no existe");
    }
}
----
Server IP: 45.112.84.4
Probable Submitter: 80.90.5.137 (proxied: 94.73.34.245)
----
Manual Page -- https://php.net/manual/en/function.autoload.php
Edit        -- https://main.php.net/note/edit/130317
Del: integrated  -- https://main.php.net/note/delete/130317/integrated
Del: useless     -- https://main.php.net/note/delete/130317/useless
Del: bad code    -- https://main.php.net/note/delete/130317/bad+code
Del: spam        -- https://main.php.net/note/delete/130317/spam
Del: non-english -- https://main.php.net/note/delete/130317/non-english
Del: in docs     -- https://main.php.net/note/delete/130317/in+docs
Del: other reasons-- https://main.php.net/note/delete/130317
Reject      -- https://main.php.net/note/reject/130317
Search      -- https://main.php.net/manage/user-notes.php
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.