bug61978.phpt 831 B

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