Created
March 18, 2013 12:14
-
-
Save akanehara/5186763 to your computer and use it in GitHub Desktop.
この equals() と hash() は矛盾しないよね?よね?
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 | |
public function equals($v0, $v1) | |
{ | |
if (is_array($v0) && is_array($v1)) { | |
return $v0 === $v1; | |
// 配列 | |
// キーと値すべてが一致 | |
} | |
if (is_object($v0) && is_object($v1)) { | |
return $v0 == $v1; | |
// オブジェクト | |
// クラスとフィールドの内容すべてが一致 | |
} | |
return $v0 === $v1; // その他 | |
} | |
public function hash($v) | |
{ | |
return sha1(serialize($v)); | |
// シリアライズしてハッシュをとる | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment