[wp-trac] [WordPress Trac] #30613: Check the return value of wp_json_encode()

WordPress Trac noreply at wordpress.org
Thu Feb 5 21:25:43 UTC 2015


#30613: Check the return value of wp_json_encode()
--------------------------+-------------------------
 Reporter:  pento         |       Owner:
     Type:  defect (bug)  |      Status:  new
 Priority:  normal        |   Milestone:  4.2
Component:  General       |     Version:  4.1
 Severity:  normal        |  Resolution:
 Keywords:  has-patch     |     Focuses:  javascript
--------------------------+-------------------------
Changes (by TobiasBg):

 * keywords:  needs-docs needs-patch => has-patch


Comment:

 [attachment:30613.2.diff] is a refreshed version of @pento's original
 patch, with
 * that errant `\` removed,
 * a short inline comment for each check,
 * all occurrences of `wp_encode_json()` in Core covered.

 Replying to [comment:7 DrewAPicture]:
 I'm not sure that I like the idea of a fourth parameter for
 `wp_json_encode()`:
 * The fourth parameter would force use to use the optional second and
 third parameters in all calls of the function, leading to ugly `0`'s and
 `512`'s popping up in the code (the default values of those parameters).
 * We are currently using `[]`, `{}`, `false`, and `''` as the fallback
 values for the error case in these sanity checks. With the checks, we
 could also move to more sophisticated error handling later (like bailing
 out early or whatever).
 * I don't think it's worth giving up readability of the checks by hiding
 the three lines in an optional function parameter.

--
Ticket URL: <https://core.trac.wordpress.org/ticket/30613#comment:8>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list