當使用可雜湊物件作為 $key 時,Map::put() 不會立即呼叫鍵上的 Hashable::hash()。例如:
<?
class Key implements \Ds\Hashable
{
protected $id;
public function __construct($id)
{
$this->id = $id;
}
public function equals($obj) : bool
{
return $this->id == $obj->id;
}
public function hash()
{
return $this->id;
}
}
$map = new \Ds\Map();
$myki = new Key('myki');
$map->put($myki, "Value String");
var_dump($map->get($myki));
echo 'Map::put() 儲存可雜湊物件,並在 toArray() 中造成錯誤'. PHP_EOL;
var_dump($map->toArray());
?>