diff --git a/reference/session/functions/session-set-save-handler.xml b/reference/session/functions/session-set-save-handler.xml
index 7a24369525..b05ac1ef78 100644
--- a/reference/session/functions/session-set-save-handler.xml
+++ b/reference/session/functions/session-set-save-handler.xml
@@ -184,6 +184,11 @@
example could easily be extended to cover database storage using your
favorite PHP supported database engine.
+
+ Note we use the OOP prototype with session_set_save_handler and
+ register the shutdown function using the function's parameter flag. This is generally
+ advised when registering objects as session save handlers.
+
- session_set_save_handler example
+ Custom session save handler using objects
The following code is for PHP versions less than 5.4.0.
@@ -257,6 +262,12 @@ session_start();
example could easily be extended to cover database storage using your
favorite PHP supported database engine.
+
+ Note we additionally register the shutdown function session_write_close
+ using register_shutdown_function under PHP less than 5.4.0.
+ This is generally advised when registering objects as session save handlers under PHP less
+ than 5.4.0.
+
When using objects as session save handlers, it is important to register the
shutdown function with PHP to avoid unexpected side-effects from the way
- PHP internally destroys objects on shutdown. Typically you should register
- 'session_write_close' using the
+ PHP internally destroys objects on shutdown and may prevent the
+ write and close from being called.
+ Typically you should register 'session_write_close' using the
register_shutdown_function function.
- As of PHP 5.4.0 you can use register_shutdown_function or
+ As of PHP 5.4.0 you can use session_register_shutdown or
simply use the 'register shutdown' flag when invoking
- session_set_save_handler using the OOP method (passing an
+ session_set_save_handler using the OOP method and passing an
instance that implements SessionHandlerInterface.
@@ -354,11 +366,14 @@ session_start();
As of PHP 5.0.5 the write and
close handlers are called after object
destruction and therefore cannot use objects or throw exceptions.
+ Exceptions are not able to be caught since will not be caught nor will
+ any exception trace be displayed and the execution will just cease unexpectedly.
The object destructors can however use sessions.
It is possible to call session_write_close from the
- destructor to solve this chicken and egg problem.
+ destructor to solve this chicken and egg problem but the most reliable way is
+ to register the shutdown function as described above.
@@ -402,6 +417,8 @@ session_start();
The session.save_handler
configuration directive
+ The register_shutdown_function
+ The session_register_shutdown for PHP 5.4.0+