From 7485e25ec1f9aa61c8b61f136c41891abbefa6c5 Mon Sep 17 00:00:00 2001 From: kenjis Date: Wed, 8 May 2024 10:01:02 +0900 Subject: [PATCH 1/5] docs: update comment --- app/Config/Exceptions.php | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/app/Config/Exceptions.php b/app/Config/Exceptions.php index c240675efb37..4e3396346b80 100644 --- a/app/Config/Exceptions.php +++ b/app/Config/Exceptions.php @@ -60,12 +60,10 @@ class Exceptions extends BaseConfig /** * -------------------------------------------------------------------------- - * LOG DEPRECATIONS INSTEAD OF THROWING? + * WHETHER TO THROW AN EXCEPTION ON DEPRECATED ERRORS * -------------------------------------------------------------------------- - * By default, CodeIgniter converts deprecations into exceptions. Also, - * starting in PHP 8.1 will cause a lot of deprecated usage warnings. - * Use this option to temporarily cease the warnings and instead log those. - * This option also works for user deprecations. + * If set to `true`, DEPRECATED errors are only logged and no exceptions are + * thrown. This option also works for user deprecations. */ public bool $logDeprecations = true; From da1203aa007563d2d3f50750705e71d1629a6d23 Mon Sep 17 00:00:00 2001 From: kenjis Date: Wed, 8 May 2024 10:01:31 +0900 Subject: [PATCH 2/5] docs: update "Logging Deprecation Warnings" It was a bit misleading. Now by default, CI4 does not throw Exceptions for deprecation errors. --- user_guide_src/source/general/errors.rst | 24 ++++++++++++++++---- user_guide_src/source/general/errors/012.php | 7 +++--- 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/user_guide_src/source/general/errors.rst b/user_guide_src/source/general/errors.rst index 2b6eafce8c33..061676aff050 100644 --- a/user_guide_src/source/general/errors.rst +++ b/user_guide_src/source/general/errors.rst @@ -94,12 +94,26 @@ Logging Deprecation Warnings .. versionadded:: 4.3.0 -By default, all errors reported by ``error_reporting()`` will be thrown as an ``ErrorException`` object. These -include both ``E_DEPRECATED`` and ``E_USER_DEPRECATED`` errors. With the surge in use of PHP 8.1+, many users -may see exceptions thrown for `passing null to non-nullable arguments of internal functions `_. -To ease the migration to PHP 8.1, you can instruct CodeIgniter to log the deprecations instead of throwing them. +Prior to v4.3.0, all errors reported by ``error_reporting()`` will be thrown as +an ``ErrorException`` object. -First, make sure your copy of ``Config\Exceptions`` is updated with the two new properties and set as follows: +But with the surge in use of PHP 8.1+, many users may see exceptions thrown for +`passing null to non-nullable arguments of internal functions `_. + +To ease the migration to PHP 8.1, starting with v4.3.0, CodeIgniter has the feature +that only logs the deprecation errors (``E_DEPRECATED`` and ``E_USER_DEPRECATED``) +without throwing them as exceptions. + +By default, CodeIgniter will only log deprecations without throwing exceptions in +development environment. In production environment, no logging is done and no +exceptions are thrown. + +Configuration +^^^^^^^^^^^^^ + +The settings for this feature are as follows. +First, make sure your copy of ``Config\Exceptions`` is updated with the two new +properties and set as follows: .. literalinclude:: errors/012.php diff --git a/user_guide_src/source/general/errors/012.php b/user_guide_src/source/general/errors/012.php index 1b773613143c..4c534b21bc1b 100644 --- a/user_guide_src/source/general/errors/012.php +++ b/user_guide_src/source/general/errors/012.php @@ -7,8 +7,9 @@ class Exceptions extends BaseConfig { - // ... other properties - - public bool $logDeprecations = true; + // ... + public bool $logDeprecations = true; // If set to false, an exception will be thrown. + // ... public string $deprecationLogLevel = LogLevel::WARNING; // this should be one of the log levels supported by PSR-3 + // ... } From 185e41bc95e0963c8bd52055827e42e961346620 Mon Sep 17 00:00:00 2001 From: kenjis Date: Wed, 8 May 2024 10:04:27 +0900 Subject: [PATCH 3/5] docs: update comment --- user_guide_src/source/general/errors/012.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/user_guide_src/source/general/errors/012.php b/user_guide_src/source/general/errors/012.php index 4c534b21bc1b..2c81e8784757 100644 --- a/user_guide_src/source/general/errors/012.php +++ b/user_guide_src/source/general/errors/012.php @@ -10,6 +10,6 @@ class Exceptions extends BaseConfig // ... public bool $logDeprecations = true; // If set to false, an exception will be thrown. // ... - public string $deprecationLogLevel = LogLevel::WARNING; // this should be one of the log levels supported by PSR-3 + public string $deprecationLogLevel = LogLevel::WARNING; // This should be one of the log levels supported by PSR-3. // ... } From 53fccdc831f3afe7ac9045230f4afb4a611cb256 Mon Sep 17 00:00:00 2001 From: kenjis Date: Wed, 8 May 2024 10:17:03 +0900 Subject: [PATCH 4/5] docs: update sample config --- user_guide_src/source/general/errors/013.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/user_guide_src/source/general/errors/013.php b/user_guide_src/source/general/errors/013.php index 23352f0ef54e..b099c6d19b3c 100644 --- a/user_guide_src/source/general/errors/013.php +++ b/user_guide_src/source/general/errors/013.php @@ -6,7 +6,8 @@ class Logger extends BaseConfig { - // .. other properties - - public $threshold = 5; // originally 4 but changed to 5 to log the warnings from the deprecations + // ... + // This must contain the log level (5 for LogLevel::WARNING) corresponding to $deprecationLogLevel. + public $threshold = (ENVIRONMENT === 'production') ? 4 : 9; + // ... } From 02c71f9c306e47ac500104b5495f6d86bcd743bf Mon Sep 17 00:00:00 2001 From: kenjis Date: Wed, 8 May 2024 10:20:10 +0900 Subject: [PATCH 5/5] docs: update description --- user_guide_src/source/general/errors.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/user_guide_src/source/general/errors.rst b/user_guide_src/source/general/errors.rst index 061676aff050..87ce25fb75a8 100644 --- a/user_guide_src/source/general/errors.rst +++ b/user_guide_src/source/general/errors.rst @@ -123,7 +123,8 @@ it accordingly. .. literalinclude:: errors/013.php -After that, subsequent deprecations will be logged instead of thrown. +After that, subsequent deprecations will be logged as configured without throwing +as exceptions. This feature also works with user deprecations: