1

I'm assuming that this is just due to the relatively new state of the SPL_Types extension. You would think this would have a predictable response.

$integer = new \SplInt( 5 );

if( false === filter_var( $integer, FILTER_VALIDATE_INT, array( 'options' => array( 'min_range' => 1, 'max_range' => 9 ) ) ) )
{
    throw new \InvalidArgumentException( sprintf( 'An integer value of 1 through 9 is required, %s "%s" given.', gettype( $integer ), $integer ) );
}

Result:

PHP Fatal error: Uncaught exception 'InvalidArgumentException' with message 'An integer value of 1 through 9 is required, object "5" given.'
CVEEP
  • 441
  • 4
  • 12
  • I guess and int and an SplInt are not the same type.. – Orangepill Jul 09 '13 at 14:31
  • 1
    You could try to cast $integer to a string in the filter_var call – Orangepill Jul 09 '13 at 14:37
  • Well, yes, typing as an `(int)` would solve the problem here. I was more annoyed with the fact that `filter_var` and `SplInt` do not play nicely together as the latter is, technically, an Object. – CVEEP Jul 09 '13 at 14:41

0 Answers0