-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
Hash::contains should return true for empty needle #8632
Comments
Changing this would mean that all datasets contain all empty needle values. I'm not convinced that this is a good idea. |
Making this change is also likely to affect existing apps. |
Yes. It changes the behavior in a backwards incompatible way. |
If this is important, and I don't think it is. You could add a third parameter called |
I tried to use this code to detect if one user has all rights another user has, and this failed, when the first user did not had any rights. I found this very confusing. I might be interesting to find out how often this method is really called with I'd vote (at least) for a |
FYI: Currently all tests pass with my proposed modification. Don't know what is about real-world-applications, though. |
@nrother Sounds like we're missing a test case 😄 |
Arrays are not sets in the mathematical definition, so this is completely counter intuitive to how the rest of the language works |
@lorenzo Do you have an example of this "rest of the language"? A quick search only reveals Still can't come up with a use-case where the current behaviour is useful... |
Yes this, for example: in_array([], ['a', []]); // true
in_array([], ['a']); // false |
I found some other inconsistencies (IMHO) in the framework: Hash::numeric(['1']) //true
Hash::numeric([]) //false
collection(['1'])->every(function($item) {return is_numeric($item);}) //true
collection([])->every(function($item) {return is_numeric($item);}) //true But this might be due to the fact that a collection is more a (mathematical) set than a hash. But somehow there seems to be a bit of confusion how to handle empty needles. |
I agree the second collection example is a bug. |
Ok, that was not what I wanted to reach 😄. In the meantime I did some research: //Java
Arrays.stream(new int[] {1}).allMatch(x -> false); //false
Arrays.stream(new int[] {}).allMatch(x -> false); //true //C#
new int[]{1}.All(x => false); //false
new int[]{}.All(x => false); //true #Python
all([False for x in [1]]) #false
all([False for x in []]) #true //CakePHP (with 64669a9)
collection([1])->every(function() {return false;}) //false
collection([])->every(function() {return false;}) //false That not what I'd expect as a developer! So for me #8670 clearly made the situation worse. and I could imagine that that even breaks someones code. (It would break mine). |
Do we want to address this for 4.0? |
I think that would be our next opportunity to do it. |
This issue is stale because it has been open for 120 days with no activity. Remove the |
I don't think there is anything to do here though. |
This is contradictory to the mathematical definition to a subset. I currently don't see a reason why
contains
should work this way. (This bug might exist due to a mixup of&&
and||
here)The text was updated successfully, but these errors were encountered: