Skip to content

Commit 95d13c5

Browse files
authored
Merge pull request #8866 from kenjis/fix-ug-logging-deprecation
docs: update "Logging Deprecation Warnings" description
2 parents 667cdcf + 02c71f9 commit 95d13c5

4 files changed

Lines changed: 33 additions & 18 deletions

File tree

app/Config/Exceptions.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,10 @@ class Exceptions extends BaseConfig
6060

6161
/**
6262
* --------------------------------------------------------------------------
63-
* LOG DEPRECATIONS INSTEAD OF THROWING?
63+
* WHETHER TO THROW AN EXCEPTION ON DEPRECATED ERRORS
6464
* --------------------------------------------------------------------------
65-
* By default, CodeIgniter converts deprecations into exceptions. Also,
66-
* starting in PHP 8.1 will cause a lot of deprecated usage warnings.
67-
* Use this option to temporarily cease the warnings and instead log those.
68-
* This option also works for user deprecations.
65+
* If set to `true`, DEPRECATED errors are only logged and no exceptions are
66+
* thrown. This option also works for user deprecations.
6967
*/
7068
public bool $logDeprecations = true;
7169

user_guide_src/source/general/errors.rst

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -94,12 +94,26 @@ Logging Deprecation Warnings
9494

9595
.. versionadded:: 4.3.0
9696

97-
By default, all errors reported by ``error_reporting()`` will be thrown as an ``ErrorException`` object. These
98-
include both ``E_DEPRECATED`` and ``E_USER_DEPRECATED`` errors. With the surge in use of PHP 8.1+, many users
99-
may see exceptions thrown for `passing null to non-nullable arguments of internal functions <https://wiki.php.net/rfc/deprecate_null_to_scalar_internal_arg>`_.
100-
To ease the migration to PHP 8.1, you can instruct CodeIgniter to log the deprecations instead of throwing them.
97+
Prior to v4.3.0, all errors reported by ``error_reporting()`` will be thrown as
98+
an ``ErrorException`` object.
10199

102-
First, make sure your copy of ``Config\Exceptions`` is updated with the two new properties and set as follows:
100+
But with the surge in use of PHP 8.1+, many users may see exceptions thrown for
101+
`passing null to non-nullable arguments of internal functions <https://wiki.php.net/rfc/deprecate_null_to_scalar_internal_arg>`_.
102+
103+
To ease the migration to PHP 8.1, starting with v4.3.0, CodeIgniter has the feature
104+
that only logs the deprecation errors (``E_DEPRECATED`` and ``E_USER_DEPRECATED``)
105+
without throwing them as exceptions.
106+
107+
By default, CodeIgniter will only log deprecations without throwing exceptions in
108+
development environment. In production environment, no logging is done and no
109+
exceptions are thrown.
110+
111+
Configuration
112+
^^^^^^^^^^^^^
113+
114+
The settings for this feature are as follows.
115+
First, make sure your copy of ``Config\Exceptions`` is updated with the two new
116+
properties and set as follows:
103117

104118
.. literalinclude:: errors/012.php
105119

@@ -109,7 +123,8 @@ it accordingly.
109123

110124
.. literalinclude:: errors/013.php
111125

112-
After that, subsequent deprecations will be logged instead of thrown.
126+
After that, subsequent deprecations will be logged as configured without throwing
127+
as exceptions.
113128

114129
This feature also works with user deprecations:
115130

user_guide_src/source/general/errors/012.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@
77

88
class Exceptions extends BaseConfig
99
{
10-
// ... other properties
11-
12-
public bool $logDeprecations = true;
13-
public string $deprecationLogLevel = LogLevel::WARNING; // this should be one of the log levels supported by PSR-3
10+
// ...
11+
public bool $logDeprecations = true; // If set to false, an exception will be thrown.
12+
// ...
13+
public string $deprecationLogLevel = LogLevel::WARNING; // This should be one of the log levels supported by PSR-3.
14+
// ...
1415
}

user_guide_src/source/general/errors/013.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66

77
class Logger extends BaseConfig
88
{
9-
// .. other properties
10-
11-
public $threshold = 5; // originally 4 but changed to 5 to log the warnings from the deprecations
9+
// ...
10+
// This must contain the log level (5 for LogLevel::WARNING) corresponding to $deprecationLogLevel.
11+
public $threshold = (ENVIRONMENT === 'production') ? 4 : 9;
12+
// ...
1213
}

0 commit comments

Comments
 (0)