Annotation of embedaddon/php/ext/json/tests/bug61978.phpt, revision 1.1.1.1

1.1       misho       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: 
                      8: class JsonTest1 {
                      9:     public $test;
                     10:     public $me;
                     11:     public function __construct() {
                     12:         $this->test = '123';
                     13:         $this->me  = $this;
                     14:     }
                     15: }
                     16: 
                     17: class JsonTest2 implements JsonSerializable {
                     18:     public $test;
                     19:     public function __construct() {
                     20:         $this->test = '123';
                     21:     }
                     22:     public function jsonSerialize() {
                     23:         return array(
                     24:             'test' => $this->test,
                     25:             'me'   => $this
                     26:         );
                     27:     }
                     28: }
                     29: 
                     30: 
                     31: $obj1 = new JsonTest1();
                     32: var_dump(json_encode($obj1));
                     33: 
                     34: echo "\n==\n";
                     35: 
                     36: $obj2 = new JsonTest2();
                     37: var_dump(json_encode($obj2));
                     38: 
                     39: ?>
                     40: --EXPECTF--
                     41: Warning: json_encode(): recursion detected in %s on line %d
                     42: string(44) "{"test":"123","me":{"test":"123","me":null}}"
                     43: 
                     44: ==
                     45: 
                     46: Warning: json_encode(): recursion detected in %s on line %d
                     47: string(44) "{"test":"123","me":{"test":"123","me":null}}"

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>