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);
Output for git.master, git.master_jit, rfc.property-hooks
Deprecated: SerializableClass implements the Serializable interface, which is deprecated. Implement __serialize() and __unserialize() instead (or in addition, if support for old PHP versions is necessary) in /in/HeLT4 on line 5 Warning: session_start(): Session cannot be started after headers have already been sent in /in/HeLT4 on line 40 Warning: session_encode(): Cannot encode non-existent session in /in/HeLT4 on line 43 Warning: session_decode(): Session data cannot be decoded when there is no active session in /in/HeLT4 on line 44 a:2:{s:4:"obj1";C:17:"SerializableClass":65:{a:1:{s:10:"sharedProp";O:8:"stdClass":1:{s:4:"name";s:4:"test";}}}s:4:"obj2";C:17:"SerializableClass":28:{a:1:{s:10:"sharedProp";r:4;}}} array(2) { ["obj1"]=> object(SerializableClass)#2 (1) { ["sharedProp"]=> object(stdClass)#1 (1) { ["name"]=> string(4) "test" } } ["obj2"]=> object(SerializableClass)#3 (1) { ["sharedProp"]=> object(stdClass)#1 (1) { ["name"]=> string(4) "test" } } }

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
59.46 ms | 403 KiB | 8 Q