Repository navigation
Conversation
Several 5.x changes add entries to docs/v4-to-v5-update.md; creating the file once keeps them from conflicting over its creation. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The package requires PHP 8.3 but still declared its API in docblocks, and count() carried #[\ReturnTypeWillChange]. Parameters, return values and properties are now typed natively. set() keeps an untyped return value because Cookie::set() returns whether the cookie was sent, and the $filter argument of get() stays untyped until getArray() no longer passes input values as filter names. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Cookie::set() handed its options to setcookie() unchanged, so cookies were written without HttpOnly, SameSite and Secure unless every caller passed them. Missing options now default to httponly = true, samesite = Lax and secure when the request uses HTTPS. set() returns whether the cookie was sent and only stores the value if it was. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Summary of Changes
Cookie::set()hands its options tosetcookie()unchanged, so every cookie is written withoutHttpOnly,SameSiteandSecureunless the caller remembers to pass them. Options that are not passed now default tohttponly => true,samesite => 'Lax'andsecure => truewhen the current request uses HTTPS ($_SERVER['HTTPS']set and notoff; proxy headers are not trusted). Options passed toset()still win.The signature becomes
set(string $name, mixed $value, array $options = []): bool: it returns the result ofsetcookie()and only stores the value in the object if the cookie was sent. ($valuestaysmixedbecauseInput::set()acceptsmixed, and a parameter cannot be narrowed in a subclass.)This is a BC break for cookies that JavaScript reads or that must be sent on cross-site requests; the update guide says what to pass for those.
Depends on #66 (native types, which types the parameters of
Input::set()soCookie::set()can type its own) and #65 (update guide); this branch contains their commits until they are merged.Testing Instructions
New tests in
CookieTest:testSetSecureDefaults()(HTTP, HTTPS,HTTPS=off),testSetOverridesDefaults()andtestSetFailure(). The first and the last fail before the change and pass after it.Documentation Changes Required
docs/overview.md("Cookies"): the defaults and the return value.docs/v4-to-v5-update.md: new section "Secure cookie defaults" with what to check.Depends on #66
🤖 Generated with Claude Code