#11537 closed defect (bug) (fixed)
Warning: Cannot modify header information… in class-json.php
Reported by: | zigazou | Owned by: | Viper007Bond |
---|---|---|---|
Milestone: | 2.9.1 | Priority: | normal |
Severity: | normal | Version: | 2.9 |
Component: | Warnings/Notices | Keywords: | |
Focuses: | Cc: |
Description
I installed the Mappress plugin and Wordpress 2.9 started showing these messages :
When displaying a page/article :
Warning: Cannot modify header information - headers already sent by (output started at /home/expote/public_html/wp-content/themes/atahualpa/header.php:2) in /home/expote/public_html/wp-includes/class-json.php on line 238
When editing a page/article :
Warning: Cannot modify header information - headers already sent by (output started at /home/expote/public_html/wp-admin/admin-header.php:18) in /home/expote/public_html/wp-includes/class-json.php on line 238
This bug occurs when :
- the PHP version does not have the json_encode function (I've got a PHP 4.4.9 version)
- a plugin tries to use the json_encode function
After looking at class-json.php, it seems odd to me that the encode method of the Services_JSON class outputs HTTP headers since it is used to emulate the json_encode of PHP 5 which does not send headers.
Attachments (2)
Change History (10)
#1
@
15 years ago
- Cc westi added
- Owner changed from westi to Viper007Bond
- Status changed from new to assigned
#2
@
15 years ago
I just checked upstream and found the output headers in version 1.0.0, the latest available when the class was committed.
1.0.1, marked as stable, is from September. Changing this the only thing marked in the changelog:
Fixed Bug #16585 - Fix correct mime type for encode() - note use encodeUnsafe() to prevent headers being sent.
Bingo! We should probably upgrade our class then.
#3
@
15 years ago
Okay, I confirmed that Viper007Bond made no changes to 1.0.0. azaozz and ryan both cleaned up whitespace but that's it.
Working on a patch.
#4
follow-up:
↓ 5
@
15 years ago
Ok.
Seems I was looking at a very old version.
Based on that should we also not be using encodeUnsafe from out json_encode function so as to not send headers and match the PHP functionality.
#5
in reply to:
↑ 4
@
15 years ago
Replying to westi:
Seems I was looking at a very old version.
Yes, but for reference, the versions you and I found are identical except for changes to the encode function (its split into encode and _encode), including the adding of headers.
Based on that should we also not be using encodeUnsafe from out json_encode function so as to not send headers and match the PHP functionality.
Yes, that sounds accurate, to me at least.
@
15 years ago
Upgrades dependency and switches WP's compat json_encode to use encodeUnsafe, so no headers are sent, to match PHP functionality.
#6
@
15 years ago
Yeah, it's just PEAR's JSON package: http://pear.php.net/package/Services_JSON
They fixed this bug in v1.0.1:
Fixed Bug #16585 - Fix correct mime type for encode() - note use encodeUnsafe() to prevent headers being sent.
So yes, updating our wrapper to use encodeUnsafe()
should do the trick.
Looking at the upstream code this is based on (http://mike.teczno.com/JSON/JSON.phps) the encode function there does not output headers either.
Need to find out why this was included in the first place - Assigning to Viper007Bond as he made those changes to the class before it was committed originally.