Make WordPress Core

Opened 15 years ago

Closed 15 years ago

Last modified 14 years ago

#11827 closed defect (bug) (fixed)

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

Reported by: alexkingorg's profile alexkingorg Owned by:
Milestone: 3.0 Priority: high
Severity: major Version: 2.9
Component: General Keywords: has-patch commit
Focuses: 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 (3)

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

Download all attachments as: .zip

Change History (13)

@alexkingorg
15 years ago

Patch to avoid double-declaration of Services_JSON class

@alexkingorg
15 years ago

More careful inclusion of Services_JSON in compat.php

#1 @nacin
15 years ago

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

#2 @alexkingorg
15 years ago

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.

#3 @azaozz
15 years ago

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.

#4 @alexkingorg
15 years ago

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

@alexkingorg
15 years ago

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

#5 @scribu
15 years ago

  • Keywords has-patch added
  • Milestone changed from Unassigned to 3.0

#6 @scribu
15 years ago

  • Version set to 2.9

#7 @scribu
15 years ago

  • Keywords commit added

#8 @azaozz
15 years ago

  • Resolution set to fixed
  • Status changed from new to closed

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

#9 @seanklein
15 years ago

Please apply this to the 2.9 Branch.

#10 @nacin
15 years ago

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.