3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php class A { protected $a = 'a'; } class B implements \JsonSerialize { protected $a; function __construct(A $a) { $this->a = $a; } public function jsonSerialize() { return [ 'a' => $this->a ]; } } $b = new B(new A()); echo json_encode($b);
based on 4Apjm
Output for 5.6.0 - 5.6.30, 7.0.0 - 7.3.0rc3
Fatal error: Interface 'JsonSerialize' not found in /in/31Ft8 on line 8
Process exited with code 255.
Output for hhvm-3.12.14 - 3.17.3
Fatal error: Uncaught Error: Undefined interface: JsonSerialize in /in/31Ft8:8 Stack trace: #0 {main}
Process exited with code 255.