PHP calls ap_set_content_type for generated content with an explicit content-type header. It calls it once at the beginning of the handler in order to set the content-type to the default (usually text/html) and then calls it again if the php script sends a Content-Type header. ap_set_content_type attaches filters configured by AddOutputFilterByType when it is called. Consequently, PHP generated pages will have both the text/html output filters and the output filters for the actual content type added. As Nick Kew says in response to bug 31226, "AddOutputFilterbyType is known to be broken." Fixing this problem does not appear to me to be easy; I would recommend documenting ap_set_content_type in include/http_protocol.h to add a warning that ap_set_content_type should not be called twice for the same request. I'm submitting this bug by way of documentation.
I think PHP should change their behavoir, and only call ap_set_content_type when they are ready to send the headers.
I can't entirely agree with either of you. Different modules may need to use ap_set_content_type without reference to each other. AddOutputFilterbyType adds a malevolent interaction that breaks modularity. Time to propose removing AddOutputFilterbyType altogether for 2.1?
*** Bug 45799 has been marked as a duplicate of this bug. ***
This is fixed in trunk by moving the directive to mod_filter. Won't backport - use mod_filter directly instead.