filterus icon indicating copy to clipboard operation
filterus copied to clipboard

String inclusion of scalar values?

Open dancrew32 opened this issue 12 years ago • 1 comments

$arr = [
  'a' => 1,
  'b' => 2,
  'c' => 3,
  4   => 4,
];

\Filterus\Filter::factory('array, keys:string')->filter($arr);

Doesn't remove 4.

I noticed you've got is_scalar() testing, then a cast to string, which takes place on 4 so that it's '4'. Was just curious why you wouldn't filter int out for alpha when array, keys:int will exclude 'a', 'b' and 'c'.

Shouldn't the string test just be is_string()? Maybe calls for the addition of array, keys:scalar?

dancrew32 avatar Jun 26 '13 00:06 dancrew32

The problem is an array can't have a key of "4". Try doing $arr["4"] = true; and you'll see that PHP internally converts the "4" into an integer. Yay to consistency.

That's why for array keys ints are accepted for strings.

ircmaxell avatar Jul 27 '15 20:07 ircmaxell