Issues

ZF-3808: Zend_Filter_Null - converts zero to null

Description

In many situations when you work with database and selecting some value from combobox (Zend_Form_Element_Select) - you need transform the "0 => '-- no value --'" to null to be compatible with database reference integrity. Therefore there should be Zend_Filter_Null for such purpose. I suggest test value for empty() and return null

Comments

Proposal added and waiting for recommendation from the devteam since 19.06.2009

I had this same problem, first built a filter Null.

But thought best and construct filter DefaultValue.

I think that this case.

code example simple in the class Filter_DefaultValue

__construct( $defaultValue = null );

filter($value) { return $defaultValue; }

This does not work for the above described case. A "true" would in your case return "null" which is not wished behaviour.

sorry me, just gave a simple example.

I had the same problem in my Applications, this filter that built, solved my problem

protected $_defaultValue;

protected $_ruleApplyValue = array();

public function __construct( $defaultValue = null , $ruleApplyValue = null )
{
    $this->_defaultValue   = $defaultValue;
    $this->_ruleApplyValue = $ruleApplyValue;

    if( !is_array( $ruleApplyValue ) ){
        $this->_ruleApplyValue = array( $ruleApplyValue );
    }
}

public function filter($value)
{
    if( in_array( $value , $this->_ruleApplyValue ) ){
        return $this->_defaultValue;
    }

    return $value;
}

call

Zend_Filter::get( 'test' , 'DefaultValue' , array( null , 'test' ) )

Closing as "Needs proposal". Proposal has been accepted New component within incubator waiting for acceptance to core since 14.09.2009.