Skip to content

Commit

Permalink
docs: update "Logging Deprecation Warnings"
Browse files Browse the repository at this point in the history
It was a bit misleading. Now by default, CI4 does not throw
Exceptions for deprecation errors.
  • Loading branch information
kenjis committed May 8, 2024
1 parent 7485e25 commit da1203a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
24 changes: 19 additions & 5 deletions user_guide_src/source/general/errors.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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 <https://wiki.php.net/rfc/deprecate_null_to_scalar_internal_arg>`_.
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 <https://wiki.php.net/rfc/deprecate_null_to_scalar_internal_arg>`_.

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

Expand Down
7 changes: 4 additions & 3 deletions user_guide_src/source/general/errors/012.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
// ...
}

0 comments on commit da1203a

Please sign in to comment.