Autoload problems in PHP

Asked

Viewed 279 times

0

I have the following autoload function of classes on my system, it is working perfectly on localhost, but when I went up to the server it gave error when including the class

Line error: 47 :: Could not include check.class.php /home/u291106554/public_html/home/_app/config.inc.php

I have already searched the subject, unsuccessfully, I have also checked the version of php that is running on the server (is in 5.5).

I need some help.

Code:

// AUTOLOAD DE CLASSES #######################
function __autoload($Class) {
$cDir = ['Conn', 'Helpers', 'Models', 'Library'];
$iDir = null;

foreach ($cDir as $dirname) {
    if (!$iDir && file_exists(__DIR__ . DIRECTORY_SEPARATOR . $dirname . DIRECTORY_SEPARATOR . $Class . '.class.php') && !is_dir(__DIR__ . DIRECTORY_SEPARATOR . $dirname . DIRECTORY_SEPARATOR . $Class . '.class.php')) {
        include_once (__DIR__ . DIRECTORY_SEPARATOR . $dirname . DIRECTORY_SEPARATOR . $Class . '.class.php');
        $iDir = TRUE;
    }
}

if (!$iDir) {
    trigger_error("Não foi possivel incluir {$Class}.class.php", E_USER_ERROR);
    die;
}
}
  • It’s linux the server?

  • Yes, I’m using Hostinger(free to test)

  • Then check the file name and the class name they should be equal, remember that linux is case sensitive windows not.

  • @rray The names are correct for both the file and the class.

  • since __autoload is as deprecated in the latest version of PHP (7.2), try using spl_autoload_register.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.