forked from php/php-src
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjson_encode_pretty_print2.phpt
56 lines (53 loc) · 1.06 KB
/
json_encode_pretty_print2.phpt
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
56
--TEST--
json_encode() with JSON_PRETTY_PRINT on declared properties
--FILE--
<?php
#[AllowDynamicProperties]
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
}
{}
{}