-
Notifications
You must be signed in to change notification settings - Fork 11.2k
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
[5.5] Fix Collection::contains() when the found value is null #21442
Conversation
@@ -217,7 +217,7 @@ public function contains($key, $operator = null, $value = null) | |||
{ | |||
if (func_num_args() == 1) { | |||
if ($this->useAsCallable($key)) { | |||
return ! is_null($this->first($key)); | |||
return $this->first($key, '__placeholder') != '__placeholder'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is that safe though? What guarantee is there that the actual value isn't __placeholder
?
In other places we've used an instance of stdClass
for these.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BTW, we should augment the with
helper to allow passing it a callback. Then this would be:
return with(new stdClass, function ($placeholder) use ($key) {
return $this->first($key, $placeholder) != $placeholder;
});
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we pleeeease get arrow functions already???
return with(new stdClass, $placeholder => $this->first($key, $placeholder) != $placeholder);
Why can't we have nice things in PHP? 😢
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
switched to using stdClass.
Because php ¯_(ツ)_/¯
I submitted a PR for the |
* upstream/5.5: (84 commits) Correct docBlock depenency on syncWithoutDetaching (laravel#21478) update v5.5 changelog allow to specify the queue while scheduling of queued jobs (laravel#21473) [5.5] Clear CountQuery "select" bindings since we're overriding the columns anyway (laravel#21468) add interface access pivot on resource update v5.5 changelog extract trait Fix docblock in Route (laravel#21454) fix test formatting Fix Relation::morphMap() merge (issue laravel#21457). (laravel#21458) extract AnonymousResourceCollection into class to allow serialization revert relationship limits Fix spelling of 'optionally' [5.5] Fix Collection::contains() when the found value is null (laravel#21442) Allow passing a callback to "with" (laravel#21445) [5.5] Add relation and model attributes in RelationNotFoundException (laravel#21426) [5.5] Make sure sql for virtual columns is added after the unsigned modifier (laravel#21441) vendor:publish options alphabetized (laravel#21412) ...
As reported in #21406
Currently
Collection::contains()
usesCollection::first()
, iffirst()
returned nullcontains
will return false even if null is the desired value.