Last active
December 14, 2015 04:28
-
-
Save akanehara/5027996 to your computer and use it in GitHub Desktop.
Ginqのデフォルトの同値比較の動作はこれでいいだろうか? distinct や groupBy で使われる予定。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class DefaultEqualityComparer implements EqualityComparer | |
{ | |
public function equals($v0, $v1, $k0, $k1) | |
{ | |
// オブジェクト | |
// (==) に委譲 | |
// 同一でなく同値。全フィールドが一致? | |
if (is_object($v0) && is_object($v1)) { | |
return $v0 == $v1; | |
} | |
// 配列 | |
// (===) に委譲 | |
// キー/値のペアが等しく、その並び順が等しく、 かつデータ型も等しい | |
if (is_array($v0) && is_array($v1)) { | |
return $v0 === $v1; | |
} | |
// それ以外の組み合わせでは (===) に委譲 | |
return $v0 === $v1; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment