fix: prevent null errors in dynamic URL path checks

Ensure the code verifies that the moodle_url object is not null before attempting to access its properties. This adjustment prevents potential errors when handling situations where the URL object might be missing, thus improving the robustness of the `mod_exp360_cm_info_dynamic` function.
This commit is contained in:
Kumi 2024-11-14 16:46:32 +01:00
parent 741addc3c8
commit 8a4c7c9113
Signed by: kumi
GPG key ID: ECBCC9082395383F

20
lib.php
View file

@ -60,17 +60,19 @@ function mod_exp360_cm_info_dynamic(cm_info $cm)
// Get the value of _url property, which is a moodle_url object
$urlObject = $urlProperty->getValue($PAGE);
// Now access the path property within the moodle_url object
$urlReflection = new ReflectionClass($urlObject);
$pathProperty = $urlReflection->getProperty('path');
$pathProperty->setAccessible(true);
if ($urlObject) {
// Now access the path property within the moodle_url object
$urlReflection = new ReflectionClass($urlObject);
$pathProperty = $urlReflection->getProperty('path');
$pathProperty->setAccessible(true);
// Get the value of the path property
$pathValue = $pathProperty->getValue($urlObject);
// Get the value of the path property
$pathValue = $pathProperty->getValue($urlObject);
// All of this only to bypass a little bug
if ($pathValue == '/course/modedit.php') {
return;
// All of this only to bypass a little bug
if ($pathValue == '/course/modedit.php') {
return;
}
}
}