3v4l.org

run code in 300+ PHP versions simultaneously
<?php 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 $sessionString; 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/NPt2R on line 3 Warning: session_start(): Session cannot be started after headers have already been sent in /in/NPt2R on line 38 Warning: session_encode(): Cannot encode non-existent session in /in/NPt2R on line 41 Warning: session_decode(): Session data cannot be decoded when there is no active session in /in/NPt2R on line 42 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:
78.57 ms | 408 KiB | 5 Q