From e78cbaa6c4d026ca23d43251ad7f9eadfb9cf9a3 Mon Sep 17 00:00:00 2001 From: Andrew Nicols Date: Tue, 7 Nov 2023 12:41:42 +0800 Subject: [PATCH 1/2] MDL-79890 core: ReflectionProperties::setValue() should take 2 args Since PHP 8.3 setValue() must be called with null as the first arg if called statically. --- lib/tests/accesslib_test.php | 2 +- .../classes/test/subplugins_test_helper_trait.php | 8 ++++---- .../tests/behat/behat_mod_bigbluebuttonbn.php | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/tests/accesslib_test.php b/lib/tests/accesslib_test.php index c610d8e58fe..ba4f0f143ac 100644 --- a/lib/tests/accesslib_test.php +++ b/lib/tests/accesslib_test.php @@ -1968,7 +1968,7 @@ class accesslib_test extends advanced_testcase { $mockedplugins->setAccessible(true); $plugins = $mockedplugins->getValue(); $plugins['fake'] = [$pluginname => "{$CFG->dirroot}/lib/tests/fixtures/fakeplugins/$pluginname"]; - $mockedplugins->setValue($plugins); + $mockedplugins->setValue(null, $plugins); update_capabilities('fake_access'); $this->resetDebugging(); // We have debugging messages here that we need to get rid of. // End of the component loader mock. diff --git a/mod/bigbluebuttonbn/classes/test/subplugins_test_helper_trait.php b/mod/bigbluebuttonbn/classes/test/subplugins_test_helper_trait.php index c3d31fe2cdd..4844865a763 100644 --- a/mod/bigbluebuttonbn/classes/test/subplugins_test_helper_trait.php +++ b/mod/bigbluebuttonbn/classes/test/subplugins_test_helper_trait.php @@ -52,13 +52,13 @@ trait subplugins_test_helper_trait { $mockedplugins->setAccessible(true); $plugins = $mockedplugins->getValue(); $plugins[extension::BBB_EXTENSION_PLUGIN_NAME] = [$pluginname => $bbbextpath . "/$pluginname"]; - $mockedplugins->setValue($plugins); + $mockedplugins->setValue(null, $plugins); $mockedplugintypes = $mockedcomponent->getProperty('plugintypes'); $mockedplugintypes->setAccessible(true); $pluginstypes = $mockedplugintypes->getValue(); $pluginstypes[extension::BBB_EXTENSION_PLUGIN_NAME] = $bbbextpath; - $mockedplugintypes->setValue($pluginstypes); + $mockedplugintypes->setValue(null, $pluginstypes); $fillclassmap = $mockedcomponent->getMethod('fill_classmap_cache'); $fillclassmap->setAccessible(true); @@ -72,7 +72,7 @@ trait subplugins_test_helper_trait { $mockedsubplugins->setAccessible(true); $subplugins = $mockedsubplugins->getValue(); $subplugins['mod_bigbluebuttonbn'][extension::BBB_EXTENSION_PLUGIN_NAME][] = $pluginname; - $mockedsubplugins->setValue($subplugins); + $mockedsubplugins->setValue(null, $subplugins); // Now write the content of the cache in a file so we can use it later. $content = core_component::get_cache_content(); @@ -149,7 +149,7 @@ trait subplugins_test_helper_trait { // Here we reset the plugin caches. $mockedplugintypes = $mockedcomponent->getProperty('plugintypes'); $mockedplugintypes->setAccessible(true); - $mockedplugintypes->setValue(null); + $mockedplugintypes->setValue(null, null); $fillclassmap = $mockedcomponent->getMethod('init'); $fillclassmap->setAccessible(true); $fillclassmap->invoke(null); diff --git a/mod/bigbluebuttonbn/tests/behat/behat_mod_bigbluebuttonbn.php b/mod/bigbluebuttonbn/tests/behat/behat_mod_bigbluebuttonbn.php index 963efc50ffb..5bda0afbd36 100644 --- a/mod/bigbluebuttonbn/tests/behat/behat_mod_bigbluebuttonbn.php +++ b/mod/bigbluebuttonbn/tests/behat/behat_mod_bigbluebuttonbn.php @@ -263,7 +263,7 @@ XPATH $mockedcomponent = new ReflectionClass(core_component::class); $mockedplugintypes = $mockedcomponent->getProperty('plugintypes'); $mockedplugintypes->setAccessible(true); - $mockedplugintypes->setValue(null); + $mockedplugintypes->setValue(null, null); $init = $mockedcomponent->getMethod('init'); $init->setAccessible(true); $init->invoke(null); From 7d4ba18a65a888ee3994a7581783c4472eab7627 Mon Sep 17 00:00:00 2001 From: Andrew Nicols Date: Tue, 7 Nov 2023 12:48:01 +0800 Subject: [PATCH 2/2] MDL-79890 core: Stop using get_class() without args PHP 8.3 deprecates the use of `get_class()` without arguments. The following alternatives should instead be used as appropriate: - `get_class($this)` - The equivalent for instance methods - `self::class` - The current class Note that the behaviour of `get_class()` in a static method was equivalent to `self::class` and _not_ `static::class`. That is to say that the previous behaviour did not respect late static binding. --- admin/tool/usertours/classes/local/target/block.php | 2 +- admin/tool/usertours/classes/local/target/selector.php | 2 +- admin/tool/usertours/classes/local/target/unattached.php | 2 +- lib/google/readme_moodle.txt | 2 ++ lib/google/src/Google/Http/REST.php | 2 +- 5 files changed, 6 insertions(+), 4 deletions(-) diff --git a/admin/tool/usertours/classes/local/target/block.php b/admin/tool/usertours/classes/local/target/block.php index 3f38f0a9062..095e9018c4c 100644 --- a/admin/tool/usertours/classes/local/target/block.php +++ b/admin/tool/usertours/classes/local/target/block.php @@ -102,7 +102,7 @@ class block extends base { */ public static function add_disabled_constraints_to_form(\MoodleQuickForm $mform) { $mform->hideIf('targetvalue_block', 'targettype', 'noteq', - \tool_usertours\target::get_target_constant_for_class(get_class())); + \tool_usertours\target::get_target_constant_for_class(self::class)); } /** diff --git a/admin/tool/usertours/classes/local/target/selector.php b/admin/tool/usertours/classes/local/target/selector.php index 3e3fd58c325..b0cc92682f0 100644 --- a/admin/tool/usertours/classes/local/target/selector.php +++ b/admin/tool/usertours/classes/local/target/selector.php @@ -92,7 +92,7 @@ class selector extends base { */ public static function add_disabled_constraints_to_form(\MoodleQuickForm $mform) { $mform->hideIf('targetvalue_selector', 'targettype', 'noteq', - \tool_usertours\target::get_target_constant_for_class(get_class())); + \tool_usertours\target::get_target_constant_for_class(self::class)); } /** diff --git a/admin/tool/usertours/classes/local/target/unattached.php b/admin/tool/usertours/classes/local/target/unattached.php index 696efe57241..316fdea4b85 100644 --- a/admin/tool/usertours/classes/local/target/unattached.php +++ b/admin/tool/usertours/classes/local/target/unattached.php @@ -81,7 +81,7 @@ class unattached extends base { * @param MoodleQuickForm $mform The form to add configuration to. */ public static function add_disabled_constraints_to_form(\MoodleQuickForm $mform) { - $myvalue = \tool_usertours\target::get_target_constant_for_class(get_class()); + $myvalue = \tool_usertours\target::get_target_constant_for_class(self::class); foreach (array_keys(self::$forcedsettings) as $settingname) { $mform->hideIf($settingname, 'targettype', 'eq', $myvalue); diff --git a/lib/google/readme_moodle.txt b/lib/google/readme_moodle.txt index 16d6f9104bb..7c7f007e020 100644 --- a/lib/google/readme_moodle.txt +++ b/lib/google/readme_moodle.txt @@ -53,6 +53,8 @@ Local changes (to reapply until upstream upgrades contain them): cd lib/google/src for file in `find . -name '*.php' `; do sed -i '/^class /i #[AllowDynamicProperties]' $file; done ``` + * MDL-46563 - PHP 8.3 compliance + - Converted use of `get_class()` to `static::class` Information ----------- diff --git a/lib/google/src/Google/Http/REST.php b/lib/google/src/Google/Http/REST.php index 2d91326f8d5..e3489d28240 100644 --- a/lib/google/src/Google/Http/REST.php +++ b/lib/google/src/Google/Http/REST.php @@ -40,7 +40,7 @@ class Google_Http_REST $runner = new Google_Task_Runner( $client, sprintf('%s %s', $req->getRequestMethod(), $req->getUrl()), - array(get_class(), 'doExecute'), + array(self::class, 'doExecute'), array($client, $req) );