Issues

ZF-3513: The "remove" family of methods in Zend_Form et al should not return Boolean

Description

The "remove" method family (Zend_Form::removeElement(), Zend_Form_DisplayGroup::removeDecorator(), Zend_Form_Element::removeValidator(), etc) should not return a Boolean but an Object. Either these methods should return the Object they remove or the Object on which the method is called, which is fairly standard behavior for pushing and popping Stack Objects. In languages where garbage collection is an issue, the Stack returns the object popped, so that it can be explicitly destroyed. In a language such as PHP where garbage collection isn't as much of an issue, the Stack should return itself, to allow additional method chaining on itself.

In the case of Zend_Form, this latter approach would be invaluable, as a developer could then perform an action such as:


$Form = new Zend_Form;
$Form->removeDecorator('FormElements')->addDecorator('Fieldset')->addDecorator('FormElements');
echo $Form;

Comments

Try Zend_Form::removeElement() after applying this patch. It returns the Zend_Form object, but throws an exception if you tried to remove an element that doesn't exist.

I meant to attach this diff rather than the whole class file.

That appears to do the job, although you may want to handle the Exception message differently, ie:

[code] throw new Zend_Form_Exception('Only form elements and groups may be overloaded; variable of type "' . $type . '" provided'); [code]

Or, alternately:

[code] throw new Zend_Form_Exception(sprintf('%s cannot remove nonexistent element: %s', getclass($this), $name)); [code]

This produces more portable code, IMO. Good job, though! Are we regular users permitted to submit patches? I know there's an official process for submitting new components and an agreement to sign, etc. Does the same process apply for patches?

Scheduling for next minor release

depends on refactoring for lazy loading (not entirely, but that's a good time to do it)

Fixed in r9919

Updating for the 1.6.0 release.