EllisPHPforum Posted November 20, 2023 Share Posted November 20, 2023 First, I am NOT a PHP coder, but I have to sort this out for my website. Briefly, the PHP was updated to Version 8 and error logs have specified two fatal errors. Quote __autoload() is no longer supported, use spl_autoload_register() instead So I did this: if ( ! function_exists('__autoload')) { AutoLoader::addFolder(array(APP_PATH.DIRECTORY_SEPARATOR.'models', APP_PATH.DIRECTORY_SEPARATOR.'controllers')); function spl__autoload__register($class_name) { AutoLoader::load($class_name); } } and Quote Array and string offset access syntax with curly braces is no longer supported So I changed $param{0} to $param(0) line 8 function get_url() { $params = func_get_args(); if (count($params) === 1) return BASE_URL . $params[0]; $url = ''; foreach ($params as $param) { if (strlen($param)) { $url .= $param(0) == '#' ? $param: '/'. $param; } } return BASE_URL . preg_replace('/^\/(.*)$/', '$1', $url); } The website is still not working. Particularly, the get_URL function returns Page Not Found Can anyone see what's wrong? Thank you. Quote Link to comment https://forums.phpfreaks.com/topic/317463-coding-update/ Share on other sites More sharing options...
kicken Posted November 20, 2023 Share Posted November 20, 2023 6 hours ago, EllisPHPforum said: So I changed $param{0} to $param(0) line 8 Arrays are accessed using square-brackets, not parenthesis. That change should have been to $param[0] 7 hours ago, EllisPHPforum said: So I did this: You don't name the function spl_autoload_register, that is a predefined function that accepts a callback. I'm assuming your original code looked like this: if ( ! function_exists('__autoload')) { AutoLoader::addFolder(array(APP_PATH.DIRECTORY_SEPARATOR.'models', APP_PATH.DIRECTORY_SEPARATOR.'controllers')); function __autoload($class_name) { AutoLoader::load($class_name); } } To update it, the easiest thing to do would be to rename the __autoload function to something unique for your application, then call the built-in spl_autoload_register function with that new name. You can also remove the if statement as it's no longer needed. AutoLoader::addFolder(array(APP_PATH.DIRECTORY_SEPARATOR.'models', APP_PATH.DIRECTORY_SEPARATOR.'controllers')); function my_app__autoload($class_name) { AutoLoader::load($class_name); } spl_autoload_register('my_app__autoload'); Quote Link to comment https://forums.phpfreaks.com/topic/317463-coding-update/#findComment-1613012 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.