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

bug when using 'some' alias for the 'contains' method Collection #26695

Closed
chapeupreto opened this issue Dec 1, 2018 · 1 comment
Closed

Comments

@chapeupreto
Copy link
Contributor

  • Laravel version: 5.7.13
  • PHP version: 7.2.12
  • Illuminate\Support\Collection

Laravel 5.7.13 introduced an alias (#26376), named some, for the contains method on the Illuminate\Support\Collection class.

Although contains is working , some is not.

For instance, this is the actual behavior using contains:

$collection = collect(['name' => 'Desk', 'price' => 100]);
$collection->contains('New York'); // false

However, when using some, the output isn't the same as contains:

$collection = collect(['name' => 'Desk', 'price' => 100]);
$collection->some('New York'); // true

Another example (same as from the Laravel documentation):

$collection = collect([1, 2, 3, 4, 5]);
$collection->contains(function ($value, $key) {
    return $value > 5;
});

// false

Now using some:

$collection = collect([1, 2, 3, 4, 5]);
$collection->some(function ($value, $key) {
    return $value > 5;
});

// PHP Warning:  explode() expects parameter 2 to be string, object given ...

I wrote a testSome() test using the same logic for the testContains() and it failed.

I believe the reason for such a odd behavior is because of the func_num_args() call used by the contains method.

Anyways, I'm going to submit a PR that tries to handle that situation.

@driesvints
Copy link
Member

Gonna close this as your PR was merged.

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