Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

__autoload replaced with spl_autoload_register for PHP 8 #47

Open
patricf opened this issue Mar 22, 2023 · 2 comments
Open

__autoload replaced with spl_autoload_register for PHP 8 #47

patricf opened this issue Mar 22, 2023 · 2 comments

Comments

@patricf
Copy link

patricf commented Mar 22, 2023

I recently upgraded my server that Histou and Nagios is running on and it went from PHP 7.1 to PHP 8.1
After this I couldn't get histou to work properly so I found this in the logs:

PHP Fatal error: __autoload() is no longer supported, use spl_autoload_register() instead in /usr/local/nagios/share/histou/histou/bootstrap.php on line 17

The __autoload() function in PHP has been removed in PHP 8 and according to the log you should replace it with spl_autoload_register() instead.

After some reading in the PHP documentation I found this to fix it:

Remove this from /usr/local/nagios/share/histou/histou/bootstrap.php:

function __autoload($className) {
    $file = strtolower(str_replace('\\', DIRECTORY_SEPARATOR, $className)).'.php';
    if (file_exists($file)) {
        require_once $file;
    }
}

And replace it with this:

function my_autoloader($className) {
    $file = strtolower(str_replace('\\', DIRECTORY_SEPARATOR, $className)).'.php';
    if (file_exists($file)) {
        require_once $file;
    }
}
spl_autoload_register('my_autoloader');

I'm not really a developer otherwise I've would have felt comfortable making a PR for this.
If anyone else wants to do it, go ahead.

This solved my issues and I'm hoping it will save someone else some time troubleshooting.

@tfmotu
Copy link

tfmotu commented Sep 10, 2023

Hi, I've the same error, but the fix does not work for me. When I try to read data from grafana I've the following error:
"
PHP Fatal error: Uncaught ArgumentCountError: Too few arguments to function {closure}(), 4 passed in /var/www/html/histou/histou/database/jsondatabase.php on line 35 and exactly 5 expected in /var/www/html/histou/index.php:16\nStack trace:\n#0 /var/www/html/histou/histou/database/jsondatabase.php(35): {closure}()\n#1 /var/www/html/histou/histou/database/influxdb.php(32): histou\database\JSONDatabase->__construct()\n#2 /var/www/html/histou/index.php(49): histou\database\Influxdb->__construct()\n#3 {main}\n thrown in /var/www/html/histou/index.php on line 16,
"
Regards

@tfmotu
Copy link

tfmotu commented Sep 10, 2023

Hi, as a lamentable workaround I can access to the graphs if I delete the code that expects the arguments from /var/www/html/histou/index.php:
"
set_error_handler(
function ($errno, $errstr, $errfile, $errline, array $errcontext) {
// error was suppressed with the @-operator
if (0 === error_reporting()) {
return false;
}
throw new ErrorException($errstr, 0, $errno, $errfile, $errline);
}
);
"
Regards

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants