Problem/Motivation
The SessionHandlerInterface has type hints now.
Also note that the return value of gc() changed in PHP 7.1:
Returns the number of deleted sessions on success, or false on failure. Note this value is returned internally to PHP for processing.
Steps to reproduce
Proposed resolution
- Type hint arguments of the
SessionHandler. - Correct the return value of the
gc()method.
Remaining tasks
User interface changes
API changes
Data model changes
Release notes snippet
Issue fork drupal-3377256
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #4
znerol commentedTransferring commit credits from #2536052-20: Remove try...catch from SessionHandler::write and 21.
Comment #5
andypostThe only question - should we keep
ReturnTypeWillChangeattribute?Comment #6
znerol commentedGood question. Let's try without.
Comment #7
smustgrave commentedTypehint didn't seem to cause any issue
New service parameter has a trigger_error and CR.
Could say this seems like a task but will leave as is.
LGTM
Comment #8
longwaveHmm, not convinced the scoping of this issue is correct - this is fixing at least four different issues, but only for this class.
Not sure we can add the return types here? If someone has extended SessionHandler and swapped it in, and replaced one of those methods without adding a return type, there is a BC break, so we have do to this in a major version change I think.
The fix to the
gc()return value looks valid.Bulk conversion to constructor property promotion is being discussed in #3278431: [May 2026] Use PHP 8 constructor property promotion for existing code
Fixing REQUEST_TIME is done in children of #2902895: [meta][no patch] Replace uses of REQUEST_TIME and time() with time service
Comment #9
znerol commentedYou are right. We cannot. Is there a way to add deprecations for methods defined in a subclass lacking the return type?
Adding type hints on the arguments is allowed as far as I can tell.
Comment #10
znerol commentedUh, ok. PHP tentative return types will likely cause serious trouble when they get enforced in PHP 9. Unless of course some PHP 8.x release will introduce more warnings for subclasses inheriting from types implementing built-in interfaces. -> https://3v4l.org/1fi6I
Comment #11
smustgrave commentedMR seemed to have CC failure.
Comment #13
znerol commentedLooks like the last reroll did not go very well (it partially reverted #2536052: Remove try...catch from SessionHandler::write). Did the reroll again and fixed the CC failure pointed out in #11.
Comment #14
spokjeComment #15
znerol commented@elber: DI injection is out of scope here, see #8.
Comment #16
znerol commented@elber: Also we regrettably cannot add returns types. Again see #8.
Comment #17
elberHi @znerol if we removed the typehints methods they aren't compatible with SessionHandlerInterface
Comment #18
znerol commentedComment #19
znerol commentedThis is incorrect.
SessionHandlerInterfaceis subject to the PHP tentative return types mechanism.Regrettably, as per #8 we cannot add return type hints in a minor release (at least not according to the current BC policy).
Comment #20
znerol commentedComment #21
znerol commentedUpdated the issue summary. Regrettably I do not have the powers necessary to remove the CR.
Comment #22
znerol commentedComment #23
smustgrave commentedLeft a comment on MR.
Comment #24
elberComment #25
smustgrave commentedBelieve this is ready.
Comment #27
catchI feel like we could probably check if contrib extends this class, and then go ahead and add return types in a minor release, based on the fact that non-base-classes are not considered @api (per https://www.drupal.org/about/core/policies/core-change-policies/bc-polic...).
However that can be a follow-up, since if someone actually is extending this, it would be better not to break them.
Committed/pushed to 11.x, thanks!
Comment #28
quietone commentedA search for SessionHanlder in contrib didn't find any case where it was extended.
Setting to NW for the followup asked for in #27.
Comment #29
quietone commentedActually set to NW
Comment #31
znerol commentedFollowup in MR !4751.
Comment #32
znerol commentedUpdated the CR.
Comment #33
smustgrave commentedOpened https://www.drupal.org/project/drupal/issues/3386766
Moving to RTBC as I don't know if MR 4751 should be closed.
Comment #34
catchLet's do the remaining work in the follow-up that's open, moving this back to fixed.
Comment #36
quietone commentedPublish the change record