summaryrefslogtreecommitdiff
path: root/ext/json/tests/json_encode_pretty_print2.phpt
blob: e872852a38d6b17616f0d51299a4be89d6f49619 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
--TEST--
json_encode() with JSON_PRETTY_PRINT on declared properties
--FILE--
<?php
class MyClass {
    public $x;
    public $y;
    public function __construct($x = 123, $y = []) {
        $this->x = $x;
        $this->y = $y;
    }
}

class HasNoProperties {}

echo json_encode(new HasNoProperties()), "\n";
echo json_encode(new HasNoProperties(), JSON_PRETTY_PRINT), "\n";

echo json_encode(new MyClass()), "\n";
echo json_encode(new MyClass(), JSON_PRETTY_PRINT), "\n";
$obj = new MyClass();
$obj->dynamic = new MyClass(null, []);
echo json_encode($obj), "\n";
echo json_encode($obj, JSON_PRETTY_PRINT), "\n";
$obj = new MyClass();
unset($obj->y);
echo json_encode($obj), "\n";
echo json_encode($obj, JSON_PRETTY_PRINT), "\n";
unset($obj->x);
echo json_encode($obj), "\n";
echo json_encode($obj, JSON_PRETTY_PRINT), "\n";
?>
--EXPECT--
{}
{}
{"x":123,"y":[]}
{
    "x": 123,
    "y": []
}
{"x":123,"y":[],"dynamic":{"x":null,"y":[]}}
{
    "x": 123,
    "y": [],
    "dynamic": {
        "x": null,
        "y": []
    }
}
{"x":123}
{
    "x": 123
}
{}
{}