From c23d5edb0f4f097eade44e7f94671ec19a785cb7 Mon Sep 17 00:00:00 2001 From: Daniel Ziegenberg Date: Sat, 5 Oct 2024 23:12:56 +0200 Subject: [PATCH] MDL-83334 core: Remove deprecated constant E_STRICT One of the error levels PHP previously emitted was E_STRICT, on code that was not strictly correct to ensure interoperability and forward compatibility. PHP 7.0 converted the majority of existing E_STRICT warnings to E_NOTICE, and since PHP 8.0, all E_STRICT notices have changed to E_NOTICE. Because all of the E_STRICT notices are upgraded to E_NOTICE since PHP 8.0, PHP 8.4 deprecates the E_STRICT constant. The E_STRICT constant is deprecated in PHP 8.4. Using the constant anywhere in PHP code now emits a deprecation notice in PHP 8.4 and later. The E_STRICT constant will be removed in PHP 9.0. PHP core and core extensions since PHP 8.0 and later do not emit E_STRICT notices at all. It is safe to assume that any PHP applications that run on PHP 8.0 and later will never encounter E_STRICT notices, and error reporting and handling can be safely updated to ignore E_STRICT notices. See: https://php.watch/versions/8.4/E_STRICT-deprecated Signed-off-by: Daniel Ziegenberg --- .github/workflows/config-template.php | 2 +- admin/cli/alternative_component_cache.php | 2 +- admin/cli/install.php | 2 +- admin/tool/behat/cli/run.php | 2 +- admin/tool/behat/cli/util.php | 2 +- admin/tool/behat/cli/util_single_run.php | 2 +- config-dist.php | 4 ++-- install.php | 2 +- lib/behat/lib.php | 5 ++--- lib/classes/component.php | 4 ++-- lib/installlib.php | 4 ++-- lib/phpunit/bootstrap.php | 6 +++--- lib/phpxmlrpc/readme_moodle.txt | 2 ++ lib/phpxmlrpc/src/Server.php | 4 +++- lib/setup.php | 8 ++++---- lib/setuplib.php | 8 ++++---- lib/tests/ajaxlib_test.php | 4 ++-- lib/tests/weblib_test.php | 2 +- mod/lesson/locallib.php | 2 -- 19 files changed, 34 insertions(+), 33 deletions(-) diff --git a/.github/workflows/config-template.php b/.github/workflows/config-template.php index dc5f958eb53..2227832ee3b 100644 --- a/.github/workflows/config-template.php +++ b/.github/workflows/config-template.php @@ -45,7 +45,7 @@ $CFG->admin = 'admin'; $CFG->directorypermissions = 0777; // Debug options - possible to be controlled by flag in future. -$CFG->debug = (E_ALL | E_STRICT); // DEBUG_DEVELOPER. +$CFG->debug = (E_ALL); // DEBUG_DEVELOPER. $CFG->debugdisplay = 1; $CFG->debugstringids = 1; // Add strings=1 to url to get string ids. $CFG->perfdebug = 15; diff --git a/admin/cli/alternative_component_cache.php b/admin/cli/alternative_component_cache.php index 6b3d454c997..97e5987b7ab 100644 --- a/admin/cli/alternative_component_cache.php +++ b/admin/cli/alternative_component_cache.php @@ -71,7 +71,7 @@ Example: exit(0); } -error_reporting(E_ALL | E_STRICT); +error_reporting(E_ALL); ini_set('display_errors', 1); $content = core_component::get_cache_content(); diff --git a/admin/cli/install.php b/admin/cli/install.php index 1f664481fb8..bd3ff805fa7 100644 --- a/admin/cli/install.php +++ b/admin/cli/install.php @@ -166,7 +166,7 @@ $CFG->running_installer = true; $CFG->early_install_lang = true; $CFG->ostype = (stristr(PHP_OS, 'win') && !stristr(PHP_OS, 'darwin')) ? 'WINDOWS' : 'UNIX'; $CFG->dboptions = array(); -$CFG->debug = (E_ALL | E_STRICT); +$CFG->debug = (E_ALL); $CFG->debugdisplay = true; $CFG->debugdeveloper = true; diff --git a/admin/tool/behat/cli/run.php b/admin/tool/behat/cli/run.php index cfcaedd96d2..c07c5b81e68 100644 --- a/admin/tool/behat/cli/run.php +++ b/admin/tool/behat/cli/run.php @@ -37,7 +37,7 @@ require_once(__DIR__.'/../../../../lib/behat/lib.php'); require_once(__DIR__.'/../../../../lib/behat/classes/behat_command.php'); require_once(__DIR__.'/../../../../lib/behat/classes/behat_config_manager.php'); -error_reporting(E_ALL | E_STRICT); +error_reporting(E_ALL); ini_set('display_errors', '1'); ini_set('log_errors', '1'); diff --git a/admin/tool/behat/cli/util.php b/admin/tool/behat/cli/util.php index 0a65b4e0a2b..3e8ce7c03db 100644 --- a/admin/tool/behat/cli/util.php +++ b/admin/tool/behat/cli/util.php @@ -121,7 +121,7 @@ require_once(__DIR__ . '/../../../../lib/behat/classes/behat_command.php'); require_once(__DIR__ . '/../../../../lib/behat/classes/behat_config_manager.php'); // Remove error handling overrides done in config.php. This is consistent with admin/tool/behat/cli/util_single_run.php. -$CFG->debug = (E_ALL | E_STRICT); +$CFG->debug = (E_ALL); $CFG->debugdisplay = 1; error_reporting($CFG->debug); ini_set('display_errors', '1'); diff --git a/admin/tool/behat/cli/util_single_run.php b/admin/tool/behat/cli/util_single_run.php index 20ef49f1322..dca67b6830a 100644 --- a/admin/tool/behat/cli/util_single_run.php +++ b/admin/tool/behat/cli/util_single_run.php @@ -117,7 +117,7 @@ define('ABORT_AFTER_CONFIG', true); require_once(__DIR__ . '/../../../../config.php'); // Remove error handling overrides done in config.php. -$CFG->debug = (E_ALL | E_STRICT); +$CFG->debug = (E_ALL); $CFG->debugdisplay = 1; error_reporting($CFG->debug); ini_set('display_errors', '1'); diff --git a/config-dist.php b/config-dist.php index 36fc1e86d2b..a8c1e7ee118 100644 --- a/config-dist.php +++ b/config-dist.php @@ -813,9 +813,9 @@ $CFG->admin = 'admin'; //========================================================================= // // Force a debugging mode regardless the settings in the site administration -// @error_reporting(E_ALL | E_STRICT); // NOT FOR PRODUCTION SERVERS! +// @error_reporting(E_ALL); // NOT FOR PRODUCTION SERVERS! // @ini_set('display_errors', '1'); // NOT FOR PRODUCTION SERVERS! -// $CFG->debug = (E_ALL | E_STRICT); // === DEBUG_DEVELOPER - NOT FOR PRODUCTION SERVERS! +// $CFG->debug = (E_ALL); // === DEBUG_DEVELOPER - NOT FOR PRODUCTION SERVERS! // $CFG->debugdisplay = 1; // NOT FOR PRODUCTION SERVERS! // // Display exceptions using the 'pretty' Whoops! utility. diff --git a/install.php b/install.php index 0878e7192a2..3077fb2f4ca 100644 --- a/install.php +++ b/install.php @@ -181,7 +181,7 @@ $CFG->umaskpermissions = (($CFG->directorypermissions & 0777) ^ 0777); $CFG->running_installer = true; $CFG->early_install_lang = true; $CFG->ostype = (stristr(PHP_OS, 'win') && !stristr(PHP_OS, 'darwin')) ? 'WINDOWS' : 'UNIX'; -$CFG->debug = (E_ALL | E_STRICT); +$CFG->debug = (E_ALL); $CFG->debugdisplay = true; $CFG->debugdeveloper = true; diff --git a/lib/behat/lib.php b/lib/behat/lib.php index 015580d1129..03233a8566d 100644 --- a/lib/behat/lib.php +++ b/lib/behat/lib.php @@ -101,7 +101,6 @@ function behat_get_error_string($errtype) { break; case E_NOTICE: case E_USER_NOTICE: - case E_STRICT: $errnostr = 'Notice'; break; case E_RECOVERABLE_ERROR: @@ -133,11 +132,11 @@ function behat_error_handler($errno, $errstr, $errfile, $errline) { return true; } - // This error handler receives E_ALL | E_STRICT, running the behat test site the debug level is + // This error handler receives E_ALL, running the behat test site the debug level is // set to DEVELOPER and will always include E_NOTICE,E_USER_NOTICE... as part of E_ALL, if the current // error_reporting() value does not include one of those levels is because it has been forced through // the moodle code (see fix_utf8() for example) in that cases we respect the forced error level value. - $respect = array(E_NOTICE, E_USER_NOTICE, E_STRICT, E_WARNING, E_USER_WARNING, E_DEPRECATED, E_USER_DEPRECATED); + $respect = [E_NOTICE, E_USER_NOTICE, E_WARNING, E_USER_WARNING, E_DEPRECATED, E_USER_DEPRECATED]; foreach ($respect as $respectable) { // If the current value does not include this kind of errors and the reported error is diff --git a/lib/classes/component.php b/lib/classes/component.php index 863424a3f4c..c9f00ee5873 100644 --- a/lib/classes/component.php +++ b/lib/classes/component.php @@ -565,7 +565,7 @@ class component { /** * Are we in developer debug mode? * - * Note: You need to set "$CFG->debug = (E_ALL | E_STRICT);" in config.php, + * Note: You need to set "$CFG->debug = (E_ALL);" in config.php, * the reason is we need to use this before we setup DB connection or caches for CFG. * * @return bool @@ -580,7 +580,7 @@ class component { return false; } - if ($debug & E_ALL && $debug & E_STRICT) { + if ($debug & E_ALL) { return true; } diff --git a/lib/installlib.php b/lib/installlib.php index 02198ae1ebf..25acef39ed0 100644 --- a/lib/installlib.php +++ b/lib/installlib.php @@ -373,9 +373,9 @@ function install_cli_database(array $options, $interactive) { require_once($CFG->libdir.'/upgradelib.php'); // show as much debug as possible - @error_reporting(E_ALL | E_STRICT); + @error_reporting(E_ALL); @ini_set('display_errors', '1'); - $CFG->debug = (E_ALL | E_STRICT); + $CFG->debug = (E_ALL); $CFG->debugdisplay = true; $CFG->debugdeveloper = true; diff --git a/lib/phpunit/bootstrap.php b/lib/phpunit/bootstrap.php index 9aedea38c3e..8916ad69765 100644 --- a/lib/phpunit/bootstrap.php +++ b/lib/phpunit/bootstrap.php @@ -33,7 +33,7 @@ if (isset($_SERVER['REMOTE_ADDR'])) { } // We want to know about all problems. -error_reporting(E_ALL | E_STRICT); +error_reporting(E_ALL); ini_set('display_errors', '1'); ini_set('log_errors', '1'); @@ -91,7 +91,7 @@ if (!defined('PHPUNIT_LONGTEST')) { } // Remove error handling overrides done in config.php. -error_reporting(E_ALL | E_STRICT); +error_reporting(E_ALL); ini_set('display_errors', '1'); ini_set('log_errors', '1'); set_time_limit(0); // No time limit in CLI scripts, user may cancel execution. @@ -217,7 +217,7 @@ unset($allowed); unset($productioncfg); // Force the same CFG settings in all sites. -$CFG->debug = (E_ALL | E_STRICT); // Can not use DEBUG_DEVELOPER yet. +$CFG->debug = (E_ALL); // Can not use DEBUG_DEVELOPER yet. $CFG->debugdeveloper = true; $CFG->debugdisplay = 1; error_reporting($CFG->debug); diff --git a/lib/phpxmlrpc/readme_moodle.txt b/lib/phpxmlrpc/readme_moodle.txt index ea0922deefe..756ce441578 100644 --- a/lib/phpxmlrpc/readme_moodle.txt +++ b/lib/phpxmlrpc/readme_moodle.txt @@ -27,3 +27,5 @@ Local changes: it has the patch, please ignore this note. * 2023-01-31 Applied patch https://github.com/gggeek/phpxmlrpc/pull/110. See MDL-76412 for more details. * readme_moodle.txt - this file ;-) + * 2025/01/17 - Server.php has minor changes for PHP 8.4 compatibility. See https://github.com/gggeek/phpxmlrpc/pull/125 and + MDL-83334 for more details. diff --git a/lib/phpxmlrpc/src/Server.php b/lib/phpxmlrpc/src/Server.php index e0436d3f60c..4b58674f33b 100644 --- a/lib/phpxmlrpc/src/Server.php +++ b/lib/phpxmlrpc/src/Server.php @@ -1416,8 +1416,10 @@ class Server } //if ($errCode != E_NOTICE && $errCode != E_WARNING && $errCode != E_USER_NOTICE && $errCode != E_USER_WARNING) - if ($errCode != E_STRICT) { + if (PHP_VERSION_ID >= 70400) { static::error_occurred($errString); + } elseif ($errCode != E_STRICT) { + static::error_occurred($errString); } // Try to avoid as much as possible disruption to the previous error handling mechanism in place diff --git a/lib/setup.php b/lib/setup.php index a120f6697fc..fc9c5fdf7cb 100644 --- a/lib/setup.php +++ b/lib/setup.php @@ -430,7 +430,7 @@ if (isset($CFG->debug)) { } else { $CFG->debug = 0; } -$CFG->debugdeveloper = (($CFG->debug & (E_ALL | E_STRICT)) === (E_ALL | E_STRICT)); // DEBUG_DEVELOPER is not available yet. +$CFG->debugdeveloper = (($CFG->debug & E_ALL) === E_ALL); // DEBUG_DEVELOPER is not available yet. if (!defined('MOODLE_INTERNAL')) { // Necessary because cli installer has to define it earlier. /** Used by library scripts to check they are being called by Moodle. */ @@ -651,14 +651,14 @@ $OUTPUT = new bootstrap_renderer(); // Set handler for uncaught exceptions - equivalent to throw new \moodle_exception() call. if (!PHPUNIT_TEST or PHPUNIT_UTIL) { set_exception_handler('default_exception_handler'); - set_error_handler('default_error_handler', E_ALL | E_STRICT); + set_error_handler('default_error_handler', E_ALL); } // Acceptance tests needs special output to capture the errors, // but not necessary for behat CLI command and init script. if (defined('BEHAT_SITE_RUNNING') && !defined('BEHAT_TEST') && !defined('BEHAT_UTIL')) { require_once(__DIR__ . '/behat/lib.php'); - set_error_handler('behat_error_handler', E_ALL | E_STRICT); + set_error_handler('behat_error_handler', E_ALL); } if (defined('WS_SERVER') && WS_SERVER) { @@ -667,7 +667,7 @@ if (defined('WS_SERVER') && WS_SERVER) { } // If there are any errors in the standard libraries we want to know! -error_reporting(E_ALL | E_STRICT); +error_reporting(E_ALL); // Just say no to link prefetching (Moz prefetching, Google Web Accelerator, others) // http://www.google.com/webmasters/faq.html#prefetchblock diff --git a/lib/setuplib.php b/lib/setuplib.php index 9ee0eccb2d7..84ef0f9059d 100644 --- a/lib/setuplib.php +++ b/lib/setuplib.php @@ -34,10 +34,10 @@ define('DEBUG_NONE', 0); define('DEBUG_MINIMAL', E_ERROR | E_PARSE); /** Errors, warnings and notices */ define('DEBUG_NORMAL', E_ERROR | E_PARSE | E_WARNING | E_NOTICE); -/** All problems except strict PHP warnings */ -define('DEBUG_ALL', E_ALL & ~E_STRICT); -/** DEBUG_ALL with all debug messages and strict warnings */ -define('DEBUG_DEVELOPER', E_ALL | E_STRICT); +/** All problems. Formerly, all problems, except the erstwhile strict PHP warnings before E_STRICT got deprecated. */ +define('DEBUG_ALL', E_ALL); +/** Same as DEBUG_ALL since E_STRICT was deprecated. */ +define('DEBUG_DEVELOPER', E_ALL); /** Remove any memory limits */ define('MEMORY_UNLIMITED', -1); diff --git a/lib/tests/ajaxlib_test.php b/lib/tests/ajaxlib_test.php index 74ffd3687f8..dc5b0a45140 100644 --- a/lib/tests/ajaxlib_test.php +++ b/lib/tests/ajaxlib_test.php @@ -116,9 +116,9 @@ final class ajaxlib_test extends \advanced_testcase { } public function test_output_capture_error_debug_all(): void { - // In error conditions, and with DEBUG_ALL set, we should not receive any output or throw any exceptions. + // In error conditions, and with DEBUG_ALL set, we should throw an exceptions. set_debugging(DEBUG_ALL); - $this->helper_test_dirty_output(); + $this->helper_test_dirty_output(true); } public function test_output_capture_error_debugdeveloper(): void { diff --git a/lib/tests/weblib_test.php b/lib/tests/weblib_test.php index 6313e1750e4..db458a3623e 100644 --- a/lib/tests/weblib_test.php +++ b/lib/tests/weblib_test.php @@ -538,7 +538,7 @@ final class weblib_test extends advanced_testcase { set_debugging(DEBUG_ALL); $this->assertEquals(DEBUG_ALL, $CFG->debug); - $this->assertFalse($CFG->debugdeveloper); + $this->assertTrue($CFG->debugdeveloper); set_debugging(DEBUG_NORMAL); $this->assertEquals(DEBUG_NORMAL, $CFG->debug); diff --git a/mod/lesson/locallib.php b/mod/lesson/locallib.php index 1f0ae12095b..8b76ab49ce0 100644 --- a/mod/lesson/locallib.php +++ b/mod/lesson/locallib.php @@ -3763,8 +3763,6 @@ abstract class lesson_base { return !empty($this->properties->{$key}); } - //NOTE: E_STRICT does not allow to change function signature! - /** * If implemented should create a new instance, save it in the DB and return it */