Ticket #11827 (closed defect (bug): fixed)

Opened 2 years ago

Last modified 19 months ago

json_encode and json_decode functions in compat.php do not safely include class-json.php

Reported by: alexkingorg Owned by:
Priority: high Milestone: 3.0
Component: General Version: 2.9
Severity: major Keywords: has-patch commit
Cc:

Description

The implementation of the json_encode and decode compatibility functions is incompatible with plugins that already included the Services_JSON class (such as my Twitter Tools plugin).

Though I wrapped the inclusion of the Services_JSON in a check in my plugin to try to keep it from being loaded twice, the conditional loading of class-json.php from compat.php happens after plugins is loaded and creates a fatal error by declaring the class a second time.

Attached are two patches, one that patches the class file in the same way class-snoopy.php handles this (recommended), the other patches compat.php.

Unfortunately, since this is in the wild already I believe plugin/theme developers will need to work around this. Suggestion to plugin/theme devs: do the same function definition approach that is in WP 2.9 rather than version sniffing.

Attachments

patch-class-json.diff Download (418 bytes) - added by alexkingorg 2 years ago.
Patch to avoid double-declaration of Services_JSON class
patch-compat.diff Download (733 bytes) - added by alexkingorg 2 years ago.
More careful inclusion of Services_JSON in compat.php
patch.2.diff Download (1.1 KB) - added by alexkingorg 2 years ago.
Standardized conditional loading in the library file for Services_JSON, SimplePie and Snoopy

Change History

Patch to avoid double-declaration of Services_JSON class

More careful inclusion of Services_JSON in compat.php

I think this makes sense for compat.php, not in class-json.php, though it should be using class_exists().

I prefer class_exists better too, but was using the code used elsewhere in WP under the assumption is was preferred for some reason. Patching the class file means every plugin/theme doesn't have to do the check, which is nice.

Seems that get_declared_classes() returns the classnames as lowercase in PHP4 and with normal capitalization in PHP5. Perhaps better to use class_exists() in Snoopy too.

Ok, here is a new patch that uses class_exists for Services_JSON, Snoopy and SimplePie.

Standardized conditional loading in the library file for Services_JSON, SimplePie and Snoopy

  • Keywords has-patch added
  • Milestone changed from Unassigned to 3.0
  • Version set to 2.9
  • Keywords commit added
  • Status changed from new to closed
  • Resolution set to fixed

(In [12705]) Safely include class-json.php, class-simplepie.php and class-snoopy.php, props alexkingorg, fixes #11827

Please apply this to the 2.9 Branch.

This was introduced in 2.9, so applying this to 2.9 does make some sense. Isn't there a way around the fatal error though?

Note: See TracTickets for help on using tickets.