ZF-213: Trim on construction

Issue Type: Improvement Created: 2006-07-09T05:08:17.000+0000 Last Updated: 2007-07-05T14:43:13.000+0000 Status: Resolved Fix version(s): - 0.6.0 (16/Dec/06)

Reporter: Oliver Saunders (irkengir) Assignee: Darby Felton (darby) Tags: - Zend_Filter

Related issues: Attachments:


Me again. I'm making a lot of use of Zend_Filter_Input atm so noticing a lot of stuff. It would be really nice if you could optionally trim all the elements of the source array.

I extended Zend_Filter_Input and actually did this

<pre class="highlight">
class SomeClass extend Zend_Filter_Input 
    const TRIM = 1;
    const WHITESPACE = 2;
     * @param array $source the data you want to filter
     * @param int $trimAll data cleaning method, use class constant
    public function __construct(array &$source, $cleaning) 
        switch ($cleaning) {
            case self::TRIM: 
                foreach ($source as $key => $value) {
                    if (is_string($value)) {    // preserve non-string types
                        $source[$key] = trim($value);
            case self::WHITESPACE:
                foreach ($source as $key => $value) {
                    if (is_string($value)) {    // preserve non-string types
                        $source[$key] = preg_replace('/\s{2,}/', ' ', $value);
                // no action
        $this->_source = $source;
        $source = null;


Posted by Darby Felton (darby) on 2006-11-07T19:26:33.000+0000

Extending the class for your specific purposes is exactly the right thing to do here. Since we will have a major refactoring of the filtering and validation technologies for 0.9.0, I do not want to mislead by placing this new and specific functionality into the existing design. Thus, instead of adding this to the current implementation, I have made a note to include such commonly-needed functionality into the new design.

Have you found an issue?

See the Overview section for more details.


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

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