Overview

Namespaces

  • PhpCommon
    • Comparison
      • Equivalence
      • Hasher

Interfaces

  • Comparable
  • Comparator
  • Equatable
  • Equivalence
  • Hashable
  • Hasher

Exceptions

  • IncomparableException
  • UnexpectedTypeException
  • Overview
  • Namespace
  • Class

Interface Equivalence

A strategy for determining whether two values are considered equivalent.

It is important to distinguish between a type that can be compared for equality and a representation of an equivalence relation. This interface is for representing the latter, while PhpCommon\Comparison\Equatable is for representing the former.

For the purpose of this interface, an equivalence relation is a binary relation that is reflexive, symmetric, transitive and consistent. Additionally, an equivalence relation can be either generic or type-specific. The "equals" relation is an example of a generic relation. Type-specific examples include:

  • "Has the same birthday as" on the set of all people.
  • "Is similar to" or "congruent to" on the set of all triangles.
  • "Has the same absolute value" on the set of real numbers.

Consult the documentation of the specific PhpCommon\Comparison\Equivalence implementation for more information about the supported types.

It is inspired by the Equivalence interface, from Guava API.

PhpCommon\Comparison\Equivalence implements PhpCommon\Comparison\Equatable

Direct known implementers

PhpCommon\Comparison\Equivalence\GenericEquivalence, PhpCommon\Comparison\Hasher

Indirect known implementers

PhpCommon\Comparison\Hasher\DateTimeHasher, PhpCommon\Comparison\Hasher\GenericHasher, PhpCommon\Comparison\Hasher\IdentityHasher, PhpCommon\Comparison\Hasher\ValueHasher
Namespace: PhpCommon\Comparison
Author: Marcos Passos marcos@marcospassos.com
Link: Guava Equivalent interface
Located at Equivalence.php
Methods summary
public boolean
# equivalent( mixed $left, mixed $right )

Checks whether the specified values are considered equivalent.

Checks whether the specified values are considered equivalent.

This method has the following properties:

  • It is reflexive: for any $x, including null, equivalent($x, $x) returns true.
  • It is symmetric: for any $x and $y, equivalent($x, $y) === equivalent($y, $x).
  • It is transitive: for any references $x, $y, and $z, if equivalent($x, $y) returns true and equivalent($y, $z) returns true, then equivalent($x, $z) returns true.
  • It is consistent: for any $x and $y, multiple invocations of equivalent($x, $y) consistently return true or consistently return false (provided that neither $x nor $y is modified).

Parameters

$left
The left-hand value to compare.
$right
The right-hand value to compare.

Returns

boolean

Returns true if the given values are considered equivalent, false otherwise.

Throws

PhpCommon\Comparison\UnexpectedTypeException

If the type of the left-hand side does not match the expected type.


PhpCommon\Comparison\IncomparableException

If the given values are not comparable under the specified equivalence relation.

Link

Equivalence relation
Methods inherited from PhpCommon\Comparison\Equatable
equals()
PHPCommon Comparison API API documentation generated by ApiGen