Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

String inclusion of scalar values? #2

Open
dancrew32 opened this issue Jun 26, 2013 · 1 comment
Open

String inclusion of scalar values? #2

dancrew32 opened this issue Jun 26, 2013 · 1 comment

Comments

@dancrew32
Copy link

$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?

@ircmaxell
Copy link
Owner

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants