From e9fcdec98b086c8a55dbbb8b09d98fe9e55b36e5 Mon Sep 17 00:00:00 2001 From: "Eloy Lafuente (stronk7)" Date: Tue, 18 Apr 2023 16:03:19 +0200 Subject: [PATCH] MDL-77953 pagelib: Ensure that null $SCRIPT continues behaving the same It's possible to have some Moodle components soft linked instead of being real directories within codebase (within dirroot). For example, Composer's "vendor" directory can be soft linked (from elsewhere), or also plugins can be installed using soft links. In those cases, Moodle calculates the $SCRIPT global as null. And, then, string operations on it are emitting a PHP deprecation message with PHP 8.1 and up. This fix just ensures that the behaviour is the same than before PHP 8.1, aka: ltrim(null) = '' (empty string), without any PHP warning. --- lib/pagelib.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/pagelib.php b/lib/pagelib.php index 4b9d7e81cac..b272c0238f1 100644 --- a/lib/pagelib.php +++ b/lib/pagelib.php @@ -1873,7 +1873,7 @@ class moodle_page { } if (is_null($script)) { - $script = ltrim($SCRIPT, '/'); + $script = ltrim($SCRIPT ?? '', '/'); $len = strlen($CFG->admin); if (substr($script, 0, $len) == $CFG->admin) { $script = 'admin' . substr($script, $len);