zendframework / zend-filter

Filter component from Zend Framework
BSD 3-Clause "New" or "Revised" License
68 stars 36 forks source link

ToInt filter doesn't transform NULL to 0 #62

Closed tasmaniski closed 6 years ago

tasmaniski commented 6 years ago

Using zend input filter I find a bug in a case when I don't send data key to the filter,
but still want to transform/filter data value. So, it should be filtered from NULL to 0

I suppose this part of the code should skip: array, object and resource

// is_scalar() does not consider NULL to be scalar
if (! is_scalar($value)) {
    return $value;
}

But unfortunately it skiped NULL value also.

Source: https://github.com/zendframework/zend-filter/blob/master/src/ToInt.php#L26

froschdesign commented 6 years ago

@tasmaniski

So, it should be filtered from NULL to 0

Sorry, this is wrong, because:

So it works like described:

Zend\Filter\ToInt allows you to transform a scalar value into an integer.

https://docs.zendframework.com/zend-filter/standard-filters/#toint