bug61978.phpt 855 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. --TEST--
  2. Bug #61978 (Object recursion not detected for classes that implement JsonSerializable)
  3. --SKIPIF--
  4. <?php if (!extension_loaded("json")) print "skip"; ?>
  5. --FILE--
  6. <?php
  7. class JsonTest1 {
  8. public $test;
  9. public $me;
  10. public function __construct() {
  11. $this->test = '123';
  12. $this->me = $this;
  13. }
  14. }
  15. class JsonTest2 implements JsonSerializable {
  16. public $test;
  17. public function __construct() {
  18. $this->test = '123';
  19. }
  20. public function jsonSerialize() {
  21. return array(
  22. 'test' => $this->test,
  23. 'me' => $this
  24. );
  25. }
  26. }
  27. $obj1 = new JsonTest1();
  28. var_dump(json_encode($obj1, JSON_PARTIAL_OUTPUT_ON_ERROR));
  29. echo "==\n";
  30. $obj2 = new JsonTest2();
  31. var_dump(json_encode($obj2, JSON_PARTIAL_OUTPUT_ON_ERROR));
  32. ?>
  33. --EXPECTF--
  34. string(44) "{"test":"123","me":{"test":"123","me":null}}"
  35. ==
  36. string(44) "{"test":"123","me":{"test":"123","me":null}}"