3
function __autoload($class) {
    if (strpos($class, 'CI_') !== 0) {
        if (file_exists($file = APPPATH . 'core/' . $class . php)) {
            include $file;
        }
    }
}

Deprecated: __autoload() is deprecated, use spl_autoload_register() and Fatal error: Cannot redeclare __autoload() error in codeigniter

IMSoP
  • 89,526
  • 13
  • 117
  • 169
  • I don't understand the question. *This is no longer in use. Use this instead.* seems very clear. Stop using `__autoload()` and use `spl_autoload_register()`. In what way could that be stated more clearly? – Ken White Jun 10 '18 at 05:06
  • First off what version of CI are you using –  Jun 10 '18 at 05:06
  • 1
    __autoload has been DEPRECATED as of PHP 7.2.0. Relying on this feature is highly discouraged. see http://php.net/manual/en/function.autoload.php – Pradeep Jun 10 '18 at 05:06
  • when use sql_autoload_register(), got error "Fatal error: Class 'Home_My_SmartPriceController' not found" – jadeja jaypalsinh Jun 10 '18 at 08:42
  • Mr. ED i use codeginiter 3 – jadeja jaypalsinh Jun 10 '18 at 08:45
  • 2
    Does this answer your question? [How to use spl\_autoload() instead of \_\_autoload()](https://stackoverflow.com/questions/10687804/how-to-use-spl-autoload-instead-of-autoload) – Nico Haase Nov 08 '21 at 15:59

2 Answers2

6

To Add spl_autoload_register() just replace this code with your code especially in routes.php

function my_autoloader($class) {
if (strpos($class, 'CI_') !== 0) {
    if (file_exists($file = APPPATH . 'core/' . $class . 'php')) {
        include $file;
    }
  }
}
spl_autoload_register('my_autoloader');

Hope this helps.

BT643
  • 3,495
  • 5
  • 34
  • 55
Jagadish Meghval
  • 199
  • 1
  • 11
  • 1
    I commented out old, added @Jagadish's code and it elminated that very annoying warning in my logs. – rolinger Mar 11 '20 at 02:24
2

I hope this one worked for you because i am using it

function your_autoloader($class) {

if (strpos($class, 'CI_') !== 0) {

    if (file_exists($file = APPPATH . 'core/' . $class . '.php')) {

        include $file;

    }
  }
}
spl_autoload_register('your_autoloader');

If this did not help you call my attension

Chibueze Agwu
  • 910
  • 5
  • 12