-
Couldn't load subscription status.
- Fork 8k
[RFC] Add json_encode indent parameter #7093
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 13 commits
40747f4
2bf91bd
98c208b
9d8a35a
727713d
548d034
5566e76
d808cdc
f2554ec
f5b8fc7
7725e9a
c34482b
1005827
7345d24
fada489
d416b4f
13d138a
f36942d
fcc1045
e7d7b4b
eea6007
574dc0c
abaa117
b8b941d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,7 +2,7 @@ | |
|
|
||
| /** @generate-class-entries */ | ||
|
|
||
| function json_encode(mixed $value, int $flags = 0, int $depth = 512): string|false {} | ||
| function json_encode(mixed $value, int $flags = 0, int $depth = 512, string|int $indent = 4): string|false {} | ||
|
||
|
|
||
| function json_decode(string $json, ?bool $associative = null, int $depth = 512, int $flags = 0): mixed {} | ||
|
|
||
|
|
||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| --TEST-- | ||
| json_encode() with JSON_PRETTY_PRINT with 2 spaces string indentation | ||
| --FILE-- | ||
| <?php | ||
|
|
||
| $data = [ | ||
| 'key' => 4, | ||
| 'other_key' => [0, 1, 2, 3] | ||
| ]; | ||
|
|
||
| echo json_encode($data, JSON_PRETTY_PRINT, 512, 2); | ||
|
|
||
| ?> | ||
| --EXPECT-- | ||
| { | ||
| "key": 4, | ||
| "other_key": [ | ||
| 0, | ||
| 1, | ||
| 2, | ||
| 3 | ||
| ] | ||
| } | ||
tdgroot marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| --TEST-- | ||
| json_encode() with JSON_PRETTY_PRINT with custom 🚀 string indentation | ||
| --FILE-- | ||
| <?php | ||
|
|
||
| $data = [ | ||
| 'key' => 4, | ||
| 'other_key' => [0, 1, 2, 3] | ||
| ]; | ||
|
|
||
| echo json_encode($data, JSON_PRETTY_PRINT, 512, '🚀'); | ||
|
|
||
| ?> | ||
| --EXPECT-- | ||
| { | ||
| 🚀"key": 4, | ||
| 🚀"other_key": [ | ||
| 🚀🚀0, | ||
| 🚀🚀1, | ||
| 🚀🚀2, | ||
| 🚀🚀3 | ||
| 🚀] | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| --TEST-- | ||
| json_encode() with JSON_PRETTY_PRINT with negative indentation | ||
| --FILE-- | ||
| <?php | ||
| echo "*** Testing json_encode() : error conditions ***\n"; | ||
|
|
||
| echo "\n-- Testing json_encode() function (JSON_PRETTY_PRINT) with negative indentation --\n"; | ||
tdgroot marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| $data = [ | ||
| 'key' => 4, | ||
| 'other_key' => [0, 1, 2, 3] | ||
| ]; | ||
|
|
||
| try { | ||
| echo json_encode($data, JSON_PRETTY_PRINT, 512, -2); | ||
| } catch (\ValueError $e) { | ||
| echo $e->getMessage() . \PHP_EOL; | ||
| } | ||
|
|
||
| ?> | ||
| --EXPECT-- | ||
| *** Testing json_encode() : error conditions *** | ||
|
|
||
| -- Testing json_encode() function (JSON_PRETTY_PRINT) with negative indentation -- | ||
| json_encode(): Argument #4 ($indent) must be either a string or a number greater than or equal to 0 | ||
Uh oh!
There was an error while loading. Please reload this page.