Skip to content

Instantly share code, notes, and snippets.

@akanehara
Created March 18, 2013 12:14
Show Gist options
  • Save akanehara/5186763 to your computer and use it in GitHub Desktop.
Save akanehara/5186763 to your computer and use it in GitHub Desktop.
この equals() と hash() は矛盾しないよね?よね?
<?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