PatrykMakowski
PatrykMakowski

Reputation: 71

HTML Error 500 when I including autoloader

This is my code. Index.php

define('_PATH', __DIR__ . '/');
require_once('libs/classloader.php');
echo 'test';

Classloader.php

function ClassLoader($className)
  {
    if(file_exists(__DIR__ '/class.'. strtolower($className) . '.php'))
    {
      require_once(__DIR__ '/class.'. strtolower($className) . '.php');
    }
    else {
      echo 'ERROR: '. $className;
    }
  }

  spl_autoload_register('ClassLoader');

I see only error 500 in my browser. PHP version is 5.4 and server is LiteSpeed.

Upvotes: 1

Views: 1372

Answers (1)

whitediver
whitediver

Reputation: 468

I think this small change should helps:

function ClassLoader($className)
{
    if(file_exists(__DIR__ .'/class.'. strtolower($className) . '.php'))
    //if(file_exists(__DIR__ '/class.'. strtolower($className) . '.php'))
    {
      require_once(__DIR__ .'/class.'. strtolower($className) . '.php');
      //require_once(__DIR__ '/class.'. strtolower($className) . '.php');
    }
    else {
      echo 'ERROR: '. $className;
    }
}

spl_autoload_register('ClassLoader');

Upvotes: 1

Related Questions