public function key() { $this->initialize(); return parent::key(); }
function key() { echo __METHOD__ . "(" . parent::key() . ")\n"; return parent::key(); }
/** * @inheritdoc */ public function key() { return $this->connections->key(); }
/** * Return the key of the current element * * @link http://php.net/manual/en/iterator.key.php * @return mixed scalar on success, or null on failure. * @since 5.0.0 */ public function key() { return $this->collection->key(); }
private function insert($breadcrumb, $position) { if ($position < 0) { $position += $this->breadcrumbs->count(); } else { // $position >= 1 $position--; } $breadcrumbs = new \SplObjectStorage(); $breadcrumbs->addAll($this->breadcrumbs); $this->breadcrumbs->removeAll($this->breadcrumbs); $breadcrumbs->rewind(); while ($breadcrumbs->valid()) { if (max(0, $position) == $breadcrumbs->key()) { $this->breadcrumbs->attach($breadcrumb); } $this->breadcrumbs->attach($breadcrumbs->current()); $breadcrumbs->next(); } }
<?php // Test code from: http://www.php.net/manual/en/splobjectstorage.getinfo.php $s = new SplObjectStorage(); $o1 = new StdClass(); $o2 = new StdClass(); $s->attach($o1, "d1"); $s->attach($o2, "d2"); $s->rewind(); while ($s->valid()) { $index = $s->key(); $object = $s->current(); // similar to current($s) $data = $s->getInfo(); var_dump($object); var_dump($data); $s->next(); } // now mutate $o2 and ensure it sticks $s->attach($o2, "mutated"); var_dump($s[$o2]);
[expect php] [file] <?php // As a map from objects to data $s = new SplObjectStorage(); $o1 = new StdClass(); $o2 = new StdClass(); $o3 = new StdClass(); $s[$o1] = "data for object 1"; $s[$o2] = "two"; $s[$o3] = 3; var_dump($s->key(), $s->valid());
/** * Move the internal pointer to an object identified by its position in the storage * @param int $key * @return bool false if the object doesn't exist */ public function selectObjectByKey($key) { if (isset($this->map[$key])) { parent::rewind(); while (parent::valid()) { if (parent::key() === $key) { return true; } parent::next(); } } return false; }
// 将参数对象从对象容器中分离 $obj->detach($o); // $obj[$o] 报错,找不到对象 // contains(object $object) // 判断对象容器是否存在该对象 $obj->contains($o); // false // count() // 获得映射对象中的对象数量 $obj->count(); // valid() // 判断对象容器当前指针后面是否有值 $obj->valid(); // key() // 返回对象容器当前节点的索引 $obj->key(); // rewind() // 返回并指向第一个节点元素 $obj->rewind(); // setInfo(mixed $data) // 给当前节点赋值。必须是调用rewind后,才可以用setInfo赋值,否则找不到对象。 $obj->setInfo('AAA'); // getInfo() // 获得当前节点的值。也必须是调用rewind后,才可以调用getInfo。 $obj->getInfo(); // current() // 获得当前节点对象 $obj->current(); // getHash() // 获得参数的hash值 $obj->getHash($a2);