filterus
filterus copied to clipboard
String inclusion of scalar values?
$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?
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.