Click here to Skip to main content
15,881,248 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Hi, I am trying to design a website using php and phpmyadmin. This website is supposed to open without difficulty. The following code is part of the execution process of the project, I have errors in lines 6.

Deprecated: __autoload() is deprecated, use spl_autoload_register() instead in C:\xampp\htdocs\components\Autoload.php on line 6


>What is causing these issues and what do I need to do to resolve them?

here the code i have:

PHP
<?php

/**
 * Функция __autoload для автоматического подключения классов
 */
function __autoload($class_name)

{

    $array_paths = array(
        '/controllers/',
        '/models/',
        '/components/',
    );

    foreach ($array_paths as $path) 
    {
        // Формируем имя и путь к файлу с классом
        $path = ROOT . $path . $class_name . '.php';

        // Если такой файл существует, подключаем его
        if (file_exists($path)) require_once($path);

    }
}


What I have tried:

PHP books, Online websites, youtube and consulting fellow colleagues.
Posted
Updated 16-Jul-23 23:18pm
v2

Read the error message: it is pretty clear:
Error
Deprecated: __autoload() is deprecated, use spl_autoload_register() instead
It even tells you exactly what you need to do to fix it!
 
Share this answer
 
Comments
честь диарио онлайн 16-Jul-23 12:52pm    
Hello, thanks for the answer, but I tried and it didn't work.!!!
You're probably getting that warning because there's technically a function already called __autoload[^] defined within PHP. I don't think you can define a function with the same name, so PHP is probably getting confused and producing the warning.

You may need to rename the function to something else.
 
Share this answer
 
v2
If you state that you tried but it "didn't work" is not helping as we do not know what did not help as we can not see what you have tried.

If you would have Googled the new function - 'spl_autolaod_register you would have found the answer easily enough - PHP's spl_autoload_register[^]

As an example given from the manual -
PHP
<?php

// function __autoload($class) {
//     include 'classes/' . $class . '.class.php';
// }

function my_autoloader($class) {
    include 'classes/' . $class . '.class.php';
}

spl_autoload_register('my_autoloader');

// Or, using an anonymous function
spl_autoload_register(function ($class) {
    include 'classes/' . $class . '.class.php';
});

?>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900