Another eye-opener from PHP is the unexpected behaviour of integer filters. Here is a test case class checking “01” and “10” whether they are integers or not.
class TestFilters extends PHPUnit_Framework_TestCase
{
public function test_filter_int_with_zero_prefix ()
{
$result = filter_var('01', FILTER_VALIDATE_INT) !== false;
$this->assertTrue($result);
}
public function test_filter_int_with_zero_suffix ()
{
$result = filter_var('10', FILTER_VALIDATE_INT) !== false;
$this->assertTrue($result);
}
}
Refer to: http://php.net/manual/en/filter.filters.validate.php
Categories: