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\InvalidArgumentExceptioninstead ofTypeError.CriticalErrornow extendsCodeIgniter\Exceptions\RuntimeExceptioninstead ofError.DatabaseExceptionnow extendsCodeIgniter\Exceptions\RuntimeExceptioninstead ofError.ConfigExceptionnow extendsCodeIgniter\Exceptions\RuntimeExceptioninstead ofCodeIgniter\Exceptions\CriticalError.TestExceptionnow extendsCodeIgniter\Exceptions\LogicExceptioninstead ofCodeIgniter\Exceptions\CriticalError.
Filter 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 a 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 its timezone set to UTC, unlike earlier versions where the currently set default timezone was used. See Upgrading Guide for details.
Time with Microseconds¶
Bugs that caused 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 did 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 the 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 the Session library forces the use of 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, the 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 the 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 the 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
DefinedRouteCollectorhas been changed. TheRouteCollectiontypehint 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
createFromTimestamp()has been changed frominttoint|float, and the return typestatichas 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
stringof the first parameter inBaseConnection::escapeIdentifier()has been removed. - The type
stringof the first parameter inBaseConnection::getFieldNames()andSQLite3\Connection::getFieldNames()has been removed. - The type
stringof the first parameter inBaseConnection::_listColumns()andMySQLi\Connection::_listColumns()andOCI8\Connection::_listColumns()andPostgre\Connection::_listColumns()andSQLSRV\Connection::_listColumns()andSQLite3\Connection::_listColumns()has been removed.
- The type
Removed Deprecated Items¶
- API: The deprecated
failValidationError()method inCodeIgniter\API\ResponseTraithas been removed. UsefailValidationErrors()instead. - HTTP: The deprecated
getReason()method inCodeIgniter\HTTP\ResponseandResponseInterfacehas 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\RedirectExceptionhas been removed. UseCodeIgniter\HTTP\Exceptions\RedirectExceptioninstead. - Constants: The deprecated constants
EVENT_PRIORITY_*have been removed. Use the class constantsCodeIgniter\Events\Events::PRIORITY_LOW,CodeIgniter\Events\Events::PRIORITY_NORMALandCodeIgniter\Events\Events::PRIORITY_HIGHinstead. - View: The deprecated property
CodeIgniter\View\View::$currentSectionhas been removed. - Config: The deprecated property
Config\Cache::$storePathhas been removed. UseConfig\Cache::$file['storePath']instead. - Formatter: The deprecated
Config\Format::getFormatter()has been removed. UseCodeIgniter\Format\Format::getFormatter()instead. - Security:
Config\Security::$samesitehas been removed. UseConfig\Cookie::$samesiteinstead. - Cookie: Methods
dispatch(),setRawCookie(),setCookie()inCodeIgniter\Cookie\CookieStorehave 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\LogicExceptionCodeIgniter\Exceptions\RuntimeExceptionCodeIgniter\Exceptions\BadFunctionCallExceptionCodeIgniter\Exceptions\BadMethodCallExceptionCodeIgniter\Exceptions\InvalidArgumentException
The following new Exception interfaces have been added:
CodeIgniter\Files\Exceptions\ExceptionInterfaceCodeIgniter\HTTP\Exceptions\ExceptionInterfaceCodeIgniter\Router\Exceptions\ExceptionInterface
Displaying exceptions for non-HTML responses now relies on the PHP display_errors setting instead of hardcoded environments.
Commands¶
- The
spark routesandspark filter:checkcommands now display filter arguments. - The
spark filter:checkcommand now displays filter classnames. - Added the
spark lang:synccommand to synchronize translation files. See Synchronizing Translation Files via Command - The
spark phpini:checkcommand now has an optionalopcacheargument, 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::$strictLocaleNegotiationto enable strict locale comparison. Previously, a response with language headersAccept-language: en-US,en-GB;q=0.9returned the first allowed languageeninstead of the exact languageen-USoren-GB. Set the value totrueto 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 number of items and the range of item numbers on the current page. See Displaying the Number of Items on the Page for more details.
Database¶
Others¶
- Added a new configuration
foundRowsfor 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
synchronousto 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()to theFileclass. See File::getSizeByBinaryUnit() and File::getSizeByMetricUnit(). - FileCollection: Added
retainMultiplePatterns()to theFileCollectionclass. See FileCollection::retainMultiplePatterns(). - Validation: Added
min_dimsvalidation rule to theFileRulesclass. See Validation. - Validation: The rules
is_uniqueandis_not_uniquenow accept the optionaldbGroupas part of the first parameter. See Validation.
Others¶
- Filters: Now you can execute a filter more than once with 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_dimsmessage - Added
Errors.badRequestandErrors.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\BadMethodCallExceptioninstead ofException. Cache\ResponseCache::get()now throwsCodeIgniter\Exceptions\RuntimeExceptioninstead ofException.- Classes that threw
RuntimeExceptionhave been changed to throwCodeIgniter\Exceptions\RuntimeException. - Classes that threw
InvalidArgumentExceptionhave been changed to throwCodeIgniter\Exceptions\InvalidArgumentException. - Classes that threw
LogicExceptionhave been changed to throwCodeIgniter\Exceptions\LogicException. - Classes that threw
BadMethodCallExceptionhave been changed to throwCodeIgniter\Exceptions\BadMethodCallException. - Classes that threw
BadFunctionCallExceptionhave been changed to throwCodeIgniter\Exceptions\BadFunctionCallException. RedirectExceptionnow extendsCodeIgniter\Exceptions\RuntimeExceptioninstead ofException.PageNotFoundExceptionnow extendsCodeIgniter\Exceptions\RuntimeExceptioninstead ofOutOfBoundsException.
Deprecations¶
- Filters:
- The properties
$argumentsand$argumentsClassofFiltershave been deprecated. No longer used. - The
Filters::getArguments()method has been deprecated. No longer used.
- The properties
- File:
- The function
getSizeByUnit()ofFilehas been deprecated. Use eithergetSizeByBinaryUnit()orgetSizeByMetricUnit()instead.
- The function
Bugs Fixed¶
- Response:
- Headers set using the
Responseclass are now prioritized and replace headers that can be set manually using the PHPheader()function.
- Headers set using the
- 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.