3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php class T implements Serializable { protected $_data = array('a' => 1, 'b' => 2, 'c' => 3, 'd' => array( 'x', 'y', 'z', )); public function serialize() { $vars = get_object_vars($this); var_dump($vars); $vars['_data']['d'] = serialize($vars['_data']['d']); var_dump($vars); return serialize($_data); } public function unserialize($vars) {} } $t = new T; var_dump(serialize($t));
based on 1XQof
Output for 5.1.0 - 7.2.0
array(1) { ["_data"]=> array(4) { ["a"]=> int(1) ["b"]=> int(2) ["c"]=> int(3) ["d"]=> array(3) { [0]=> string(1) "x" [1]=> string(1) "y" [2]=> string(1) "z" } } } array(1) { ["_data"]=> array(4) { ["a"]=> int(1) ["b"]=> int(2) ["c"]=> int(3) ["d"]=> string(42) "a:3:{i:0;s:1:"x";i:1;s:1:"y";i:2;s:1:"z";}" } } Notice: Undefined variable: _data in /in/kPQ6n on line 15 string(14) "C:1:"T":2:{N;}"
Output for 5.0.5
Fatal error: Interface 'Serializable' not found in /in/kPQ6n on line 3
Process exited with code 255.
Output for 5.0.0 - 5.0.4
Fatal error: Class 'Serializable' not found in /in/kPQ6n on line 3
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_STRING, expecting '{' in /in/kPQ6n on line 3
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1
Parse error: parse error, unexpected T_STRING, expecting '{' in /in/kPQ6n on line 3
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `'{'' in /in/kPQ6n on line 3
Process exited with code 255.