#11827 closed defect (bug) (fixed)
json_encode and json_decode functions in compat.php do not safely include class-json.php
Reported by: | 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)
Change History (13)
#1
@
15 years ago
I think this makes sense for compat.php, not in class-json.php, though it should be using class_exists().
#2
@
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
@
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
@
15 years ago
Ok, here is a new patch that uses class_exists for Services_JSON, Snoopy and SimplePie.
@
15 years ago
Standardized conditional loading in the library file for Services_JSON, SimplePie and Snoopy
Patch to avoid double-declaration of Services_JSON class