ext-ds: PHP 7 - Wrong Vector/Map/Set equality

I think creating a different issue from #65 is a better idea.

Current problem

var_dump(new \Ds\Set([1, 3]) == new \Ds\Set([1, 2, 3])); // true

it makes me very sad as I definitively can’t rely on Ds in my tests. And I use Ds everywhere as it does a really nice job (thanks for that anyway)

Solution

Is there any reason why this behavior ? And is it a bug or a known behavior ? Looks too big that anyone complain about it ^^

Whatever I’m definitively open to contribute event if my C skill are very old because it cannot stay like that.

I already had a look on the (clean) code. I guess we need to implements the compare_objects handlers on the internal htable ? Looks pretty obvious, I know. May be we can even use the toArray and rely on array::compare_objects ? Is there any stuff that prevent us to do that ?

Anyway, let me know what I can do to help on this very annoying issue.

Thanks

About this issue

  • Original URL
  • State: open
  • Created 8 years ago
  • Comments: 66 (38 by maintainers)

Most upvoted comments

Hi everyone. 👋

My plan for comparison behavior in 2.0:

  • Abandon the polyfill 🔪
  • Hash-based structures only support object-keys that implement Hashable.
  • interface Hashable extends Equatable
  • Overload == for all classes that implement Equatable.
  • Use the equivalent of === for everything else (scalars, arrays, etc).
  • Two objects can only be equal if they are also instances of the same class.
  • The only Hashable collection will be Tuple, which is immutable.

Constraining the roadmap according to a polyfill is a big mistake IMHO. The polyfill makes no sense for production use. For any other purpose, I believe that an IDE plugin or just stubs are the way to go.

It’s such a shame to abandon the polyfill.

@rtheunissen this is the right decision to me. I’ve abandoned this extension because of this kind of issues and honestly if all of that is because of the polyfill kill it!

I’d like to keep them consistent, otherwise it invalidates the polyfill to some extent. Maybe if and when the extension becomes a default, we can drop the polyfill.

@shouze happy to do it with equals. Added to 2.0, see #65

@rtheunissen Yes-ish. I’d assume you wouldn’t want to have the same comparison semantics as a property comparison would give you. In particular, those would be weak and I doubt you’d want to have Set(["foo"]) == Set([true]), right?

@nikic would this actually be implicit if we implement the get_properties handler?