Repository navigation
[zend-session] fix php 8.4+ deprecation when setting a save handler - #245
Open
falkenhawk wants to merge 1 commit into
Open
falkenhawk wants to merge 1 commit into
falkenhawk wants to merge 1 commit into
Conversation
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.
1) php 8.4: deprecation when a save handler is set
Zend_Session::setSaveHandler()passes the six methods of the save handler tosession_set_save_handler()one by one.php 8.4 deprecated that, so every app using a save handler, e.g.
Zend_Session_SaveHandler_DbTable, gets this on every request:On php 8.4+ the save handler is now wrapped in a new
Zend_Session_SaveHandler_SessionHandlerAdapter, which implementsSessionHandlerInterface.Nothing changes on older php versions.
The adapter makes php treat the save handler exactly as before:
$register_shutdown = false, because the old way did not close the session on shutdown eithercreate_sid(),validateId()andupdateTimestamp()methods of the registered object. The adapter is registered instead of the save handler, so such methods of a save handler stay unused, as before.2) php 8.6:
create_sid()andvalidateId()php 8.6 warns about classes implementing
SessionHandlerInterfacewithoutcreate_sid()andvalidateId(), php 9 will require them (rfc).The adapter has both, and they behave like php's built-in defaults for the old way:
create_sid()creates the session id with php's default generator (session_create_id())validateId()accepts every session id, sosession.use_strict_modehas no effect, as beforevalidateId()whether such an id already exists, to avoid collisions insession_regenerate_id()andsession_create_id(). php skipped this check for the old way, so the adapter answers "no". Otherwisesession_create_id()would fail during an active session.3) Session tests
DbTableTest::testSessionSavingran in unit test mode, so the save handler was never registered and the test passed without asserting anything. It now uses a real session, and it fails without the fix on php 8.4+.SessionHandlerAdapterTestchecks the pass-through and the session id handling. The session id tests run a real session in a separate process, with the same assertions on all php versions: the old way below php 8.4, the adapter from php 8.4 on.Zend_SessionTest::testSetExpireSessionHopsandtestSetExpireSessionVarsByHopsOnUsefailed on php 8.1+. The helper script prints nothing once the session namespace has expired, andexplode()gotnullfromarray_pop()on the empty output. Same fix as diablomedia/zf1-session#145.Other forks
nullfromread()becomesfalse), still closes the session on shutdown, and has nocreate_sid()andvalidateId()for php 8.6.setSaveHandler()only acceptsSessionHandlerInterfaceobjects, so existing save handlers no longer work.Zend_Session_SaveHandler_InterfaceextendsSessionHandlerInterfacewith return types, so existing save handlers have to be changed, and php 8 is required.Ported from a private repository, based on work by @marcing.