3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php class A { private $json = "{\"prop1\": 1}"; public function __toString() { return $this->json; } } $obj = new \stdClass; $obj->prop0 = new A; var_dump(json_encode($obj)); var_dump((string) $obj);
based on 9BtOc
Output for 7.1.0 - 7.2.0
string(12) "{"prop0":{}}" Recoverable fatal error: Object of class stdClass could not be converted to string in /in/keOiA on line 11
Process exited with code 255.
Output for 5.4.0 - 7.0.20
string(12) "{"prop0":{}}" Catchable fatal error: Object of class stdClass could not be converted to string in /in/keOiA on line 11
Process exited with code 255.