1--TEST--
2json_encode() with JSON_PRETTY_PRINT on declared properties
3--FILE--
4<?php
5#[AllowDynamicProperties]
6class MyClass {
7    public $x;
8    public $y;
9    public function __construct($x = 123, $y = []) {
10        $this->x = $x;
11        $this->y = $y;
12    }
13}
14
15class HasNoProperties {}
16
17echo json_encode(new HasNoProperties()), "\n";
18echo json_encode(new HasNoProperties(), JSON_PRETTY_PRINT), "\n";
19
20echo json_encode(new MyClass()), "\n";
21echo json_encode(new MyClass(), JSON_PRETTY_PRINT), "\n";
22$obj = new MyClass();
23$obj->dynamic = new MyClass(null, []);
24echo json_encode($obj), "\n";
25echo json_encode($obj, JSON_PRETTY_PRINT), "\n";
26$obj = new MyClass();
27unset($obj->y);
28echo json_encode($obj), "\n";
29echo json_encode($obj, JSON_PRETTY_PRINT), "\n";
30unset($obj->x);
31echo json_encode($obj), "\n";
32echo json_encode($obj, JSON_PRETTY_PRINT), "\n";
33?>
34--EXPECT--
35{}
36{}
37{"x":123,"y":[]}
38{
39    "x": 123,
40    "y": []
41}
42{"x":123,"y":[],"dynamic":{"x":null,"y":[]}}
43{
44    "x": 123,
45    "y": [],
46    "dynamic": {
47        "x": null,
48        "y": []
49    }
50}
51{"x":123}
52{
53    "x": 123
54}
55{}
56{}
57