puiu91
4/6/2016 - 4:17 AM

PHP spl_autoload_register for linux servers

PHP spl_autoload_register for linux servers

<?php

// instantiate SPL (Standard PHP Library) Autoloader
spl_autoload_register(function($class) {

    // base directory for the namespace prefix
    $baseDirectory = 'C:\Users\AdminUser\Documents\App\' . DIRECTORY_SEPARATOR;

    // build file path
    $file = $baseDirectory . $class . '.php';

    if (file_exists($file)) {
        require $file;
    }

});

<?php

// instantiate SPL (Standard PHP Library) Autoloader
spl_autoload_register(function ($class) {

    // replace namespace separators with directory separators and append with .php
    $file = str_replace('\\', '/', $class . '.php');

    if (file_exists($file)) {
        require $file;
    }

});