User defined session serializer View as Markdown

Declined
Authors
Yasuo Ohgaki yohgaki@ohgaki.net
Date
2016-11-17
Version
1.0
Source
wiki.php.net/rfc/user_defined_session_serializer

Vote

Add user defined session serializer closed
Yes
9
No
10
19 voters
bwoebi No 2016-12-05 22:10
danack No 2016-12-06 17:14
guilhermeblanco Yes 2016-12-09 04:25
hywan No 2016-12-05 11:46
kalle Yes 2016-12-05 08:36
kguest Yes 2016-12-09 14:44
leigh No 2016-12-06 13:53
levim No 2016-12-06 00:49
lstrojny Yes 2016-12-05 11:56
mariano Yes 2016-12-05 15:17
mfischer Yes 2016-12-05 07:30
nikic No 2016-12-05 22:53
ocramius No 2016-12-05 02:09
peehaa No 2016-12-05 08:20
pierrick No 2016-12-16 16:24
remi Yes 2016-12-05 14:03
ryat No 2016-12-06 02:17
yohgaki Yes 2016-12-05 03:14
yunosh Yes 2016-12-05 10:49

Discussions on the mailing list

[RFC DISCUSSION] User defined session serializer
by Yasuo Ohgaki · 4 messages
[RFC][VOTE] User defined session serializer
by Yasuo Ohgaki · 26 messages

RFC text

Copied from wiki.php.net, last synchronized Oct 13, 2026 11:52 UTC

Introduction

Currently, only C module can add additional session data serializer. With user defined session data serializer, users can

  • Encrypt/decrypt session data transparently.
  • Use any serialization format such as JSON/XML/etc.
  • Add invisible data to session data for session data management purpose.
  • Validate session data via hash_hmac().

Proposal

Add session serializer registration function.

bool session_set_serializer(callable $serialize_func, callable $unserialize_func)

$serialize_func and $unserialize_func are:

$serialize_func = function(array $session_data_array) {
  // User can add/encrypt data in this function
  // Returning anything other than string raises E_RECOVERABLE_ERROR
  return serialize($session_data_array); // Must return string
}
 
$unserialize_func = function(string $session_data_string) {
  // User can remove/decrypt/validate data in this function
  // Returning anything other than array raises E_RECOVERABLE_ERROR
  return unserialize($session_data_string); // Must return array
}

Add session serializer interface.

interface SessionSerializerInterface {
  function encode(array $session_data_array):string;
  function decode(string $serialized_session_data_string):array;
}

session_set_serializer() accepts object implements SessionSerializerInterface.

bool session_set_serializer(SessionSerializerInterface $handler)

These functions/methods are called before reading/writing session data to session data database.

Please refer to the pull request phpt files for usage details.

Backward Incompatible Changes

None.

Proposed PHP Version(s)

Next PHP. Currently 7.2.

Future Scope

Current session modules OO user save handler uses internal save handler as its base object. This design caused many problems.

User defined session serializer can get rid of this design issue. There will be new and clean OO session save handler interface proposal. This RFC keeps extendability for new OO session save handler API.

Proposed Voting Choices

2/3 majority is required to pass.

Vote starts: 2016-12-05 Vote ends: 2016-12-19 UTC 23:59:59

Vote: Add user defined session serializer — Yes: 9 · No: 10 (closed)

Patches and Tests

Implementation

After the project is implemented, this section should contain

  1. the version(s) it was merged to
  2. a link to the git commit(s)
  3. a link to the PHP manual entry for the feature
  4. a link to the language specification section (if any)

References

Links to external references, discussions or RFCs