Opened 12 years ago
Closed 12 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 |
|---|---|---|---|
| Priority: | low | Milestone: | 4.1 |
| Component: | General | Version: | 4.1 |
| Severity: | minor | Keywords: | has-patch |
| Cc: | Focuses: |
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).
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
I added it to
compat.phpinstead ofdefault-constants.phpbecause it’s not our constant — it’s part of our PHP compat layer. But I don't feel strongly about that.