[wp-trac] [WordPress Trac] #30139: Allow JSON_PRETTY_PRINT to be used without notice on PHP < 5.4
WordPress Trac
noreply at wordpress.org
Tue Oct 28 18:56:36 UTC 2014
#30139: Allow JSON_PRETTY_PRINT to be used without notice on PHP < 5.4
--------------------------+-------------------
Reporter: markjaquith | Owner:
Type: defect (bug) | Status: new
Priority: low | Milestone: 4.1
Component: General | Version: trunk
Severity: minor | Keywords:
Focuses: |
--------------------------+-------------------
`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).
--
Ticket URL: <https://core.trac.wordpress.org/ticket/30139>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list