refactor: do not override Exception's $code in RedirectException - #10465
Open
paulbalandan wants to merge 1 commit into
Open
refactor: do not override Exception's $code in RedirectException#10465paulbalandan wants to merge 1 commit into
Exception's $code in RedirectException#10465paulbalandan wants to merge 1 commit into
Conversation
paulbalandan
force-pushed
the
redirect-exception-status-code
branch
from
August 16, 2026 19:06
bd18ac0 to
0dadf42
Compare
Exception's $code in RedirectExceptionException's $code in RedirectException
There was a problem hiding this comment.
Pull request overview
Refactors RedirectException to separate HTTP redirect status from the inherited exception code. Assessed as targeting the 4.8 minor line.
Changes:
- Adds
$defaultStatusCodefor response redirects. - Removes the resolved PHPStan baseline error.
- Documents the compatibility change.
Validation: Static review only; automated validation left to CI.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
system/HTTP/Exceptions/RedirectException.php |
Introduces the dedicated redirect status property. |
utils/phpstan-baseline/property.phpDocType.neon |
Removes the resolved property-type error. |
utils/phpstan-baseline/loader.neon |
Updates the total baseline count. |
user_guide_src/source/changelogs/v4.8.0.rst |
Records the breaking extension-point change. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| * Status code applied to a Response that arrives without a 3xx redirect status. | ||
| */ | ||
| protected $code = 302; | ||
| protected int $defaultStatusCode = 302; |
| - **Filters:** HTTP method matching for method-based filters is now case-sensitive. The keys in ``Config\Filters::$methods`` must exactly match the request method | ||
| (e.g., ``GET``, ``POST``). Lowercase method names (e.g., ``post``) will no longer match. | ||
| - **HTTP:** Routes defined with ``$routes->add()`` now also match HTTP ``QUERY`` requests. If the route has CSRF protection, remember that CSRF verification does not protect safe methods such as ``GET`` and ``QUERY``. | ||
| - **HTTP:** ``CodeIgniter\HTTP\Exceptions\RedirectException`` no longer redeclares the inherited ``$code`` property. The status applied to a ``Response`` passed to the constructor without a 3xx status now comes from the new ``protected int $defaultStatusCode = 302`` property. Subclasses that overrode ``$code`` to change that status must override ``$defaultStatusCode`` instead. |
| * HTTP status code for redirects | ||
| * | ||
| * @var int | ||
| * Status code applied to a Response that arrives without a 3xx redirect status. |
| - **Filters:** HTTP method matching for method-based filters is now case-sensitive. The keys in ``Config\Filters::$methods`` must exactly match the request method | ||
| (e.g., ``GET``, ``POST``). Lowercase method names (e.g., ``post``) will no longer match. | ||
| - **HTTP:** Routes defined with ``$routes->add()`` now also match HTTP ``QUERY`` requests. If the route has CSRF protection, remember that CSRF verification does not protect safe methods such as ``GET`` and ``QUERY``. | ||
| - **HTTP:** ``CodeIgniter\HTTP\Exceptions\RedirectException`` no longer redeclares the inherited ``$code`` property. The status applied to a ``Response`` passed to the constructor without a 3xx status now comes from the new ``protected int $defaultStatusCode = 302`` property. Subclasses that overrode ``$code`` to change that status must override ``$defaultStatusCode`` instead. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
RedirectExceptionredeclares the$codeproperty from the baseException. It is untyped, so we cannot natively declare aninttype as it would fatal, nor add a phpdoc as phpstan will complain you're narrowing an invariant property. Moreover, the$codeproperty is used here as the HTTP status code not the exception code. Thus, this PR proposes uses another property for the status code.Checklist: