note 125172 added to ds-map.toarray

From: Date: Tue, 07 Jul 2020 06:57:34 +0000
Subject: note 125172 added to ds-map.toarray
Groups: php.notes 
Request: Send a blank email to php-notes+get-214840@lists.php.net to get a copy of this message
When using Hashable object as $key, Map::put() will not call the Hashable::hash() on the key until later. For example <? 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() store the Hashable object and it cause error in toArray()'. PHP_EOL; var_dump($map->toArray()); ?> ---- Server IP: 45.112.84.4 Probable Submitter: 101.0.109.162 (proxied: 121.214.107.91) ---- Manual Page -- http://php.net/manual/en/ds-map.toarray.php Edit -- https://master.php.net/note/edit/125172 Del: integrated -- https://master.php.net/note/delete/125172/integrated Del: useless -- https://master.php.net/note/delete/125172/useless Del: bad code -- https://master.php.net/note/delete/125172/bad+code Del: spam -- https://master.php.net/note/delete/125172/spam Del: non-english -- https://master.php.net/note/delete/125172/non-english Del: in docs -- https://master.php.net/note/delete/125172/in+docs Del: other reasons-- https://master.php.net/note/delete/125172 Reject -- https://master.php.net/note/reject/125172 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#214840) next »