HTML Error 500 when I including autoloader

1.3k Views Asked by At

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.

1

There are 1 best solutions below

2
On BEST ANSWER

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');