Easy Solution for Learndash Fatal Error: Uncaught Type Error Due to PHP 8.1 : Solve Easily !

LearnDash Installation Fatal Error
LearnDash Installation Fatal Error

Have you encountered this recent phenomenon of Learndash installation fatal error giving message of Uncaught Type Error ? This is true for new installations or updates of Learndash on a WordPress running on PHP version 8.1. If you experienced a problem like the one given below, don’t worry. We have a solution.

Fatal Error Message while Installing Learndash on WordPress with  Version Php 8.1

Fatal error: Uncaught TypeError: substr_replace(): Argument #3 ($offset) must be of type array|int, bool given in C:\xampp\htdocs\wordpress\wp-content\plugins\learndash-hub\framework\class-controller.php:45 Stack trace: #0 C:\xampp\htdocs\wordpress\wp-content\plugins\learndash-hub\framework\class-controller.php(45): substr_replace(‘C:\\xampp\\htdocs…’, ”, false) #1 C:\xampp\htdocs\wordpress\wp-content\plugins\learndash-hub\src\controller\class-signin-controller.php(20): LearnDash\Hub\Framework\Controller->__construct() #2 C:\xampp\htdocs\wordpress\wp-content\plugins\learndash-hub\src\boot.php(38): LearnDash\Hub\Controller\Signin_Controller->__construct() #3 C:\xampp\htdocs\wordpress\wp-includes\class-wp-hook.php(307): LearnDash\Hub\Boot->start(”) #4 C:\xampp\htdocs\wordpress\wp-includes\class-wp-hook.php(331): WP_Hook->apply_filters(NULL, Array) #5 C:\xampp\htdocs\wordpress\wp-includes\plugin.php(476): WP_Hook->do_action(Array) #6 C:\xampp\htdocs\wordpress\wp-settings.php(598): do_action(‘init’) #7 C:\xampp\htdocs\wordpress\wp-config.php(96): require_once(‘C:\\xampp\\htdocs…’) #8 C:\xampp\htdocs\wordpress\wp-load.php(50): require_once(‘C:\\xampp\\htdocs…’) #9 C:\xampp\htdocs\wordpress\wp-admin\admin.php(34): require_once(‘C:\\xampp\\htdocs…’) #10 C:\xampp\htdocs\wordpress\wp-admin\plugins.php(10): require_once(‘C:\\xampp\\htdocs…’) #11 {main} thrown in C:\xampp\htdocs\wordpress\wp-content\plugins\learndash-hub\framework\class-controller.php on line 45

Why LearnDash Installation Fatal Error Happening ?

Simple. Due to  WordPress running on PHP version 8.1. The problem has started because WordPress is now updating to higher PHP versions. But all the codes in plugins or themes specifically are not updated to version 8.1 of the PHP. So, codes that were written for PHP version 7.4 will not be properly parsed in version 8.1, because the syntax of the PHP in the new avatar may have changed.

The solution to Fatal Error: Uncaught Type Error

Give a closer look at the fatal error message. The last line in bold shows where the problem exists. As per the example fatal error message, a  type error has happened on line 45 in the file called class-controller.php which is inside the folder  learndash-hub\framework\

So, if you are facing a similar error, here is what to do. Go to the file where the error occurred, find the  erroneous code, and replace it with the following code:

function trailingslashit($tmp_path) {
		return untrailingslashit( $string ) . '/controller';
}

After updating the code if you still face some errors, do comment down below so we can look at it and find some efficient solutions.

Demo of Solution for Learndash Installation Fatal Error

Thank you for reading the article. If you are looking for awesome LearnDash plugins do check out this website.