ZF-10367: public Zend_Mail::clearHeader() method?

Issue Type: New Feature Created: 2010-08-23T01:59:10.000+0000 Last Updated: 2010-11-10T10:04:43.000+0000 Status: Resolved Fix version(s): - 1.11.0 (02/Nov/10)

Reporter: Jon Nott (jonnott) Assignee: Marc Hodgins (mjh_ca) Tags: - Zend_Mail

Related issues: Attachments: - ZF-10367.patch


Many of the things you set with public add_() methods on a Zend_Mail object, you can remove again using corresponding clear_() methods, but this isn't the case with headers.

There is the protected Zend_Mail::_clearHeader() method, but (unless I'm missing something) there isn't a clear reason why this isn't safe to have a public method for. One shouldn't have to extend Zend_Mail just to clear a header, when there's already methods like clearRecipients(), clearSubject() etc.

The usage scenario where this would be handy is when you're looping through recipients within the same Zend_Mail instance, changing some things (e.g. clearRecipients()->addTo('') ), then calling send() again. You might've also added some custom header with addHeader() which you then want to remove and add differently for the next recipient. Presently this is only possible by extending Zend_Mail, or creating a new Zend_Mail instance for each recipient (which may get problematic if you have things like attachments in the mix).

A public clearHeader() method could be as simple as:

<pre class="highlight">
        public function clearHeader($headerName)
            return $this;


Posted by Marc Hodgins (mjh_ca) on 2010-10-25T17:52:24.000+0000

Patch with test attached. Maintains protected _clearHeader() method as a proxy for backwards compatibility for classes that have extended Zend_Mail.

Posted by Jon Nott (jonnott) on 2010-10-26T02:23:42.000+0000

Would be interesting to know why _clearRecipients() was made a protected method to begin with? Any ideas?

Posted by Dolf Schimmel (Freeaqingme) (freak) on 2010-10-26T04:56:32.000+0000

I don't know why the original author, of one of its successors did it like this. I suppose because he doesn't want the enduser to call it (doh ;D). Zend_Mail suffers from a lot of this kind of decisions and a bad API-design alltogether. That is why I plan to do a rewrite of its core for ZF2, so we have something that actually works.

Posted by Matthew Weier O'Phinney (matthew) on 2010-10-26T05:51:05.000+0000

Patch applied to trunk and 1.11 release branch -- thanks!

Posted by Jon Nott (jonnott) on 2010-11-10T10:04:43.000+0000

Interestingly, on the subject of backwards-compatibility, this provides an example of how having to work around weaknesses in the API can actually cause a kind of backwards-incompatibility where framework users have extended classes to provide those work-arounds.

For example, my work-around for the lack of a public clearHeader() method in Zend_Mail was to create a method in an extended class which did the reverse of what this patch now does (see my original description above). So if I upgrade now from ZF 1.10 to 1.11, I actually have to remove my extended public method to avoid an infinite-loop method calling scenario.


Have you found an issue?

See the Overview section for more details.


© 2006-2018 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.