WordPress.org

Make WordPress Core

Opened 4 years ago

Closed 4 years ago

Last modified 4 years ago

#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)

class-json_1.0.1.diff (810 bytes) - added by nacin 4 years ago.
11537.2.diff (1.1 KB) - added by nacin 4 years ago.
Upgrades dependency and switches WP's compat json_encode to use encodeUnsafe, so no headers are sent, to match PHP functionality.

Download all attachments as: .zip

Change History (10)

comment:1 westi4 years ago

  • Cc westi added
  • Owner changed from westi to Viper007Bond
  • Status changed from new to assigned

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.

comment:2 nacin4 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.

comment:3 nacin4 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.

nacin4 years ago

comment:4 follow-up: westi4 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.

comment:5 in reply to: ↑ 4 nacin4 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.

nacin4 years ago

Upgrades dependency and switches WP's compat json_encode to use encodeUnsafe, so no headers are sent, to match PHP functionality.

comment:6 Viper007Bond4 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.

comment:7 ryan4 years ago

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

(In [12491]) Update json lib. Use encodeUnsafe in our json wrapper. Props nacin. fixes #11537 for trunk

comment:8 ryan4 years ago

(In [12492]) Update json lib. Use encodeUnsafe in our json wrapper. Props nacin. fixes #11537 for 2.9

Note: See TracTickets for help on using tickets.