3v4l.org

run code in 300+ PHP versions simultaneously
<?php ini_set('session.serialize_handler', 'php_serialize'); class SerializableClass implements Serializable { public $sharedProp; public function __construct($prop) { $this->sharedProp = $prop; } public function __set($key, $value) { $this->$key = $value; } public function serialize() { return serialize(get_object_vars($this)); } public function unserialize($data) { $ar = unserialize($data); if ($ar === false) { return; } foreach ($ar as $k => $v) { $this->__set($k, $v); } } } // Shared object that acts as property of two another objects stored in session $testPropertyObj = new stdClass(); $testPropertyObj->name = 'test'; // Two instances of \SerializableClass that shares property $sessionObject = [ 'obj1' => new SerializableClass($testPropertyObj), 'obj2' => new SerializableClass($testPropertyObj), ]; session_start(); $_SESSION = $sessionObject; $sessionString = session_encode(); session_decode($sessionString); echo serialize($sessionObject) . "\n"; echo $sessionString . "\n"; echo "\n\n"; var_dump($_SESSION);

preferences:
57.17 ms | 402 KiB | 5 Q