Version 4.6.0
Release Date: January 19, 2025
4.6.0 release of CodeIgniter4
BREAKING
Behavior Changes
Exceptions
The exception class has been redesigned. See Exception Design for details. The following breaking changes have been made accordingly:
Validation::setRule()
now throwsCodeIgniter\Exceptions\InvalidArgumentException
instead ofTypeError
.CriticalError
now extendsCodeIgniter\Exceptions\RuntimeException
instead ofError
.DatabaseException
now extendsCodeIgniter\Exceptions\RuntimeException
instead ofError
.ConfigException
now extendsCodeIgniter\Exceptions\RuntimeException
instead ofCodeIgniter\Exceptions\CriticalError
.TestException
now extendsCodeIgniter\Exceptions\LogicException
instead ofCodeIgniter\Exceptions\CriticalError
.
Filters Changes
The Filters
class has been changed to allow multiple runs of the same filter
with different arguments in before or after. See
Upgrading Guide for details.
Registrars
Added check to prevent Auto-Discovery of Registrars from running twice. If it is executed twice, an exception will be thrown. See Registrars with Dirty Hack.
Time::createFromTimestamp()
Time::createFromTimestamp()
handles timezones differently. If $timezone
is not explicitly passed then the instance has timezone set to UTC unlike earlier
where the currently set default timezone was used.
See Upgrading Guide for details.
Time with Microseconds
Fixed bugs that some methods in Time
to lose microseconds have been fixed.
See Upgrading Guide for details.
Time::setTimestamp()
Time::setTimestamp()
behavior has been fixed.
See Upgrading Guide for details.
Error Reporting to Non-HTML Requests
In previous versions, when a request does not accept HTML, CodeIgniter showed
error details only in the development
and testing
environments.
But because it is not possible to display error details when using a custom
environment, this behavior has been fixed so that error details are displayed if
display_errors
in PHP ini setting is enabled.
With this fix, the error details are now displayed under the same conditions for both HTML requests and non-HTML requests.
Session ID (SID)
Now Session
library forces to use the PHP default 32 character SIDs, with 4
bits of entropy per character.
See Upgrading Guide for details.
Headers
The headers set by the Response
class replace those that can be set by the PHP
header()
function.
In previous versions, headers set by the Response
class were added to existing
ones - giving no options to change them. That could lead to unexpected behavior when
the same headers were set with mutually exclusive directives.
For example, session will automatically set headers with the header()
function:
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate
Pragma: no-cache
So if we set Expires header one more time we will end up with a duplicated header:
$response->removeHeader('Expires'); // has no effect
return $response->setHeader('Expires', 'Sun, 17 Nov 2024 14:17:37 GMT');
Response headers:
Expires: Thu, 19 Nov 1981 08:52:00 GMT
// ...
Expires: Sun, 17 Nov 2024 14:17:37 GMT
Now, we don’t know which one will be picked by the browser or which header is the correct one. With changes in this version our previous header will be overridden:
Cache-Control: no-store, no-cache, must-revalidate
Pragma: no-cache
Expires: Sun, 17 Nov 2024 14:17:37 GMT
Interface Changes
Note
As long as you have not extended the relevant CodeIgniter core classes or implemented these interfaces, all these changes are backward compatible and require no intervention.
Router: The following methods have been added in
RouteCollectionInterface
:getDefaultNamespace()
getRoutesOptions()
setHTTPVerb()
isFiltered()
getFiltersForRoute()
Method Signature Changes
Router: The constructor of the
DefinedRouteCollector
has been changed. TheRouteCollection
typehint has been changed toRouteCollectionInterface
.View: The return type of the
renderSection()
method has been changed tostring
, and now the method does not callecho
.Time: The first parameter type of the
createFromTimestamp()
has been changed fromint
toint|float
, and the return typestatic
has been added.Helpers:
character_limiter()
parameter names have been updated. If you use named arguments, you need to update the function calls.
Removed Type Definitions
- Database:
The type
string
of the first parameter inBaseConnection::escapeIdentifier()
has been removed.The type
string
of the first parameter inBaseConnection::getFieldNames()
andSQLite3\Connection::getFieldNames()
have been removed.The type
string
of the first parameter inBaseConnection::_listColumns()
andMySQLi\Connection::_listColumns()
andOCI8\Connection::_listColumns()
andPostgre\Connection::_listColumns()
andSQLSRV\Connection::_listColumns()
andSQLite3\Connection::_listColumns()
have been removed.
Removed Deprecated Items
API: The deprecated
failValidationError()
method inCodeIgniter\API\ResponseTrait
has been removed. UsefailValidationErrors()
instead.HTTP: The deprecated
getReason()
method inCodeIgniter\HTTP\Response
andResponseInterface
has been removed. UsegetReasonPhrase()
instead.Logger: The deprecated
CodeIgniter\Log\Logger::cleanFilenames()
andCodeIgniter\Test\TestLogger::cleanup()
have been removed. Use theclean_path()
function instead.Router: The deprecated
CodeIgniter\Router\Exceptions\RedirectException
has been removed. UseCodeIgniter\HTTP\Exceptions\RedirectException
instead.Constants: The deprecated constants
EVENT_PRIORITY_*
in has been removed. Use the class constantsCodeIgniter\Events\Events::PRIORITY_LOW
,CodeIgniter\Events\Events::PRIORITY_NORMAL
andCodeIgniter\Events\Events::PRIORITY_HIGH
instead.View: The deprecated property
CodeIgniter\View\View::$currentSection
has been removed.Config: The deprecated property
Config\Cache::$storePath
has been removed. UseConfig\Cache::$file['storePath']
instead.Formatter: The deprecated
Config\Format::getFormatter()
has been removed. UseCodeIgniter\Format\Format::getFormatter()
instead.Security:
Config\Security::$samesite
has been removed. UseConfig\Cookie::$samesite
instead.Cookie: Methods
dispatch()
,setRawCookie()
,setCookie()
inCodeIgniter\Cookie\CookieStore
has been removed. They are now part ofCodeIgniter\HTTP\ResponseTrait
.
Enhancements
Publisher
Publisher::discover()
now accepts a second parameter (namespace
) specifying the namespace in which publishers should be searched. See Discovery in a specific namespace for the details.
Exceptions
The exception class has been redesigned. See Exception Design for details. The following new Exception classes have been added accordingly:
CodeIgniter\Exceptions\LogicException
CodeIgniter\Exceptions\RuntimeException
CodeIgniter\Exceptions\BadFunctionCallException
CodeIgniter\Exceptions\BadMethodCallException
CodeIgniter\Exceptions\InvalidArgumentException
The following new Exception interfaces have been added:
CodeIgniter\Files\Exceptions\ExceptionInterface
CodeIgniter\HTTP\Exceptions\ExceptionInterface
CodeIgniter\Router\Exceptions\ExceptionInterface
Displaying exceptions for non-HTML responses now rely on the PHP display_errors
setting instead of hardcoded environments.
Commands
The
spark routes
andspark filter:check
commands now display filter arguments.The
spark filter:check
command now displays filter classnames.The
spark lang:sync
command to synchronize translation files. See Synchronization Translation Files via CommandThe
spark phpini:check
command now has an optionalopcache
argument, which when used will display information about opcache settings.
Routing
Now you can specify multiple hostnames when restricting routes.
Negotiator
Added a feature flag
Feature::$strictLocaleNegotiation
to enable strict locale comparision. Previously, response with language headersAccept-language: en-US,en-GB;q=0.9
returned the first allowed languageen
could instead of the exact languageen-US
oren-GB
. Set the value totrue
to enable comparison not only by language code (‘en’ - ISO 639-1) but also by regional code (‘en-US’ - ISO 639-1 plus ISO 3166-1 alpha).
Pagination
Added a new feature to get the total and the range number of items of the current page. See Displaying the Number of Items on the Page for more details.
Database
Others
Added a new configuration
foundRows
for MySQLi to useMYSQLI_CLIENT_FOUND_ROWS
.Added the
BaseConnection::resetTransStatus()
method to reset the transaction status. See Resetting Transaction Status for details.SQLite3 has a new Config item
synchronous
to adjust how strict SQLite is at flushing to disk during transactions. Modifying this can be useful if we use journal mode set toWAL
.
Libraries
File: Added
getSizeByBinaryUnit()
andgetSizeByMetricUnit()
toFile
class. See File::getSizeByBinaryUnit() and File::getSizeByMetricUnit().FileCollection: Added
retainMultiplePatterns()
toFileCollection
class. See FileCollection::retainMultiplePatterns().Validation: Added
min_dims
validation rule toFileRules
class. See Validation.Validation: Rules:
is_unique
andis_not_unique
now accept the optionaldbGroup
as part of the first parameter. See Validation.
Others
Filters: Now you can execute a filter more than once with the different arguments in before or after.
Services: Added
BaseService::resetServicesCache()
method to reset the services cache. See Resetting Services Cache.Errors: Added a default error page for “400 Bad Request”.
Message Changes
Added
Validation.min_dims
messageAdded
Errors.badRequest
andErrors.sorryBadRequest
Changes
Exceptions
The exception classes have been redesigned. See Exception Design for details. The following changes have been made accordingly:
The
deleteMatching()
method in Cache Handler classes now throwsCodeIgniter\Exceptions\BadMethodCallException
instead ofException
.Cache\ResponseCache::get()
now throwsCodeIgniter\Exceptions\RuntimeException
instead ofException
.Classes that threw
RuntimeException
have been changed to throwCodeIgniter\Exceptions\RuntimeException
.Classes that threw
InvalidArgumentException
have been changed to throwCodeIgniter\Exceptions\InvalidArgumentException
.Classes that threw
LogicException
have been changed to throwCodeIgniter\Exceptions\LogicException
.Classes that threw
BadMethodCallException
have been changed to throwCodeIgniter\Exceptions\BadMethodCallException
.Classes that threw
BadFunctionCallException
have been changed to throwCodeIgniter\Exceptions\BadFunctionCallException
.RedirectException
now extendsCodeIgniter\Exceptions\RuntimeException
instead ofException
.PageNotFoundException
now extendsCodeIgniter\Exceptions\RuntimeException
instead ofOutOfBoundsException
.
Deprecations
- Filters:
The properties
$arguments
and$argumentsClass
ofFilters
have been deprecated. No longer used.The
Filters::getArguments()
method has been deprecated. No longer used.
- File:
The function
getSizeByUnit()
ofFile
has been deprecated. Use eithergetSizeByBinaryUnit()
orgetSizeByMetricUnit()
instead.
Bugs Fixed
- Response:
Headers set using the
Response
class are now prioritized and replace headers that can be set manually using the PHPheader()
function.
View: Added support for multibyte strings for
View::excerpt()
.Helpers: Added support for multibyte strings for
excerpt()
.
See the repo’s CHANGELOG.md for a complete list of bugs fixed.