Giter Site home page Giter Site logo

Comments (4)

iluuu1994 avatar iluuu1994 commented on May 14, 2024 3

That comes down to how array_intersect works.

https://www.php.net/manual/en/function.array-intersect.php

Note: Two elements are considered equal if and only if (string) $elem1 === (string) $elem2. In words: when the string representation is the same.

array_intersect will also not work for other objects that don't implement __toString and it might unintentionally match objects that coincidentally return the same string. I think at this point we'd be better off adding a new array_intersect alternative that uses strict comparison instead.

Any change here will likely require an RFC.

from php-src.

damianwadley avatar damianwadley commented on May 14, 2024 2

Related is that there was a deliberate decision to not support automatically converting backed enums to their backed type for the time being. As mentioned, implementing that will come in a future RFC after enums have settled into common usage.

I think at this point we'd be better off adding a new array_intersect alternative that uses strict comparison instead.

Sorting would still be required to reach O(n log n) efficiency that the various array comparison functions offer. Using only equality would mean settling for the naive O(n^2) algorithm - which could also be trivially implemented in userland if there was a need to work with arrays containing unsortable items like enums.

Now, what to do with this issue? I'm not sure. On the old tracker I'd resolve as Suspended, but those did have a tendency to get lost and forgotten over time. At the very least this isn't actionable now or in the foreseeable future, and there is the fact that array_intersect and enums are actually behaving as intended...

from php-src.

iluuu1994 avatar iluuu1994 commented on May 14, 2024 2

For the reasons stated by @damianwadley I'll close the issue. array_intersection is working as documented, for better or worse. I personally am in favor of a more complete standard library but not all core members are. In any case, this would require an RFC.

from php-src.

mattjanssen avatar mattjanssen commented on May 14, 2024

Still hoping this becomes possible in the future 🤞 but I understand why it's not yet.

from php-src.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.