Skip to content

refactor: do not override Exception's $code in RedirectException - #10465

Open
paulbalandan wants to merge 1 commit into
codeigniter4:4.8from
paulbalandan:redirect-exception-status-code
Open

refactor: do not override Exception's $code in RedirectException#10465
paulbalandan wants to merge 1 commit into
codeigniter4:4.8from
paulbalandan:redirect-exception-status-code

Conversation

@paulbalandan

Copy link
Copy Markdown
Member

Description
RedirectException redeclares the $code property from the base Exception. It is untyped, so we cannot natively declare an int type as it would fatal, nor add a phpdoc as phpstan will complain you're narrowing an invariant property. Moreover, the $code property is used here as the HTTP status code not the exception code. Thus, this PR proposes uses another property for the status code.

Checklist:

  • Securely signed commits
  • Component(s) with PHPDoc blocks, only if necessary or adds value (without duplication)
  • Unit testing, with >80% coverage
  • User guide updated
  • Conforms to style guide

@paulbalandan paulbalandan added refactor Pull requests that refactor code breaking change Pull requests that may break existing functionalities labels Aug 16, 2026
@paulbalandan
paulbalandan force-pushed the redirect-exception-status-code branch from bd18ac0 to 0dadf42 Compare August 16, 2026 19:06
@github-actions github-actions Bot added the 4.8 PRs that target the `4.8` branch. label Aug 16, 2026
@paulbalandan paulbalandan changed the title refactor: do nor override Exception's $code in RedirectException refactor: do not override Exception's $code in RedirectException Aug 16, 2026
@paulbalandan
paulbalandan requested a balanced review from Copilot August 16, 2026 19:11

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 $defaultStatusCode for 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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

4.8 PRs that target the `4.8` branch. breaking change Pull requests that may break existing functionalities refactor Pull requests that refactor code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants