Opened 10 years ago
Closed 10 years ago
#30139 closed defect (bug) (fixed)
Allow JSON_PRETTY_PRINT to be used without notice on PHP < 5.4
Reported by: | markjaquith | Owned by: | markjaquith |
---|---|---|---|
Milestone: | 4.1 | Priority: | low |
Severity: | minor | Version: | 4.1 |
Component: | General | Keywords: | has-patch |
Focuses: | Cc: |
Description
JSON_PRETTY_PRINT
was introduced in PHP 5.4. If you attempt to use it in PHP < 5.4 as an option passed to json_encode()
or wp_json_encode()
, you'll get a notice about the undefined constant.
As it is just a human-readable thing and doesn't functionally affect the output of the JSON, we should just define the constant if it’s not defined. That way people can use it without doing a version check, and if PHP supports it, they get pretty output, otherwise, they silently get standard non-pretty output. I don't think we should add other constants, because they do affect the functionality of the output, and so silent failure would be a bad thing.
See also #29435 and #28786 (wp_json_encode()
will support the option as well, on PHP versions that can accept the options argument).
Attachments (1)
Change History (5)
#1
@
10 years ago
- Keywords has-patch added
- Owner set to markjaquith
- Status changed from new to accepted
I added it to
compat.php
instead ofdefault-constants.php
because it’s not our constant — it’s part of our PHP compat layer. But I don't feel strongly about that.