-
Bug
-
Resolution: Fixed
-
Blocker
-
4.5.2
On a fresh Moodle 4.5.2 install, accessing Moodle without the new router feature works as intended but trying to use it leads to this error :
Fatal error: Uncaught TypeError: core\router::guess_basepath(): Return value must be of type string, null returned in /appli/moodle/www/lib/classes/router.php:115
|
Stack trace:
|
#0 /appli/moodle/www/lib/classes/router.php(79): core\router->guess_basepath()
|
#1 /appli/moodle/www/lib/php-di/php-di/src/Definition/Resolver/ObjectCreator.php(129): core\router->__construct()
|
#2 /appli/moodle/www/lib/php-di/php-di/src/Definition/Resolver/ObjectCreator.php(56): DI\Definition\Resolver\ObjectCreator->createInstance()
|
#3 /appli/moodle/www/lib/php-di/php-di/src/Definition/Resolver/ResolverDispatcher.php(60): DI\Definition\Resolver\ObjectCreator->resolve()
|
#4 /appli/moodle/www/lib/php-di/php-di/src/Container.php(353): DI\Definition\Resolver\ResolverDispatcher->resolve()
|
#5 /appli/moodle/www/lib/php-di/php-di/src/Container.php(136): DI\Container->resolveDefinition()
|
#6 /appli/moodle/www/lib/classes/di.php(62): DI\Container->get()
|
#7 /appli/moodle/www/r.php(54): core\di::get()
|
#8 {main} thrown in /appli/moodle/www/lib/classes/router.php on line 115
|
This seems to be caused by line 94 of lib/classes/router.php :
/** |
* Guess the basepath for the Router.
|
*
|
* @return string
|
*/
|
protected function guess_basepath(): string { |
global $CFG; // Moodle is not guaranteed to exist at the domain root. |
// Strip out the current script. |
$scriptroot = parse_url($CFG->wwwroot, PHP_URL_PATH); // <--- This one (L94) |
|
// --- redacted some more string processing --- |
|
return $scriptroot; |
}
|
The function "parse_url" returns null because there is no "path part" in $CFG->wwwroot when Moodle is accessed directly at the root. I suspect it doesn't create an issue when Moodle is accessed via a sub-path since the sub-path would be returned instead of null.
Adding a trailing slash to the wwwroot to make parse_url not return null obviously causes the wwwrootslash error.