/** * {@inheritdoc} */ public function getItem($index) { if (!$this->items->offsetExists($index)) { throw new \OutOfBoundsException('The index ' . $index . ' is not set'); } return $this->items[$index]; }
/** * @param int $offset * @return mixed */ public function offsetGet($offset) { if (!$this->set->offsetExists($offset)) { throw new \OutOfRangeException('Nothing found at this offset'); } return $this->set->offsetGet($offset); }
/** * If $index is below zero, we know that it does not exist. * * This was added to be compatible with HHVM 3.2.0. * Note that HHVM 3.3.0 no longer requires this work around. * * @param int $index * * @return bool */ public function offsetExists($index) { return $index >= 0 && parent::offsetExists($index); }
<?php $array = new SplFixedArray(5); $a = $array->offsetExists(); if (is_null($a)) { echo 'PASS'; }
<?php $array = new SplFixedArray(5); if ($array->offsetExists(-10) === false) { echo 'PASS'; }
public function offsetExists($n) { echo "A::offsetExists\n"; return parent::offsetExists($n); }
$array->rewind(); // current() // 获得当前节点 $array->current(); // next() // 指针移动到下一个节点 $array->next(); // setSize(int $size) // 重新设置阵列数组的大小 $array->setSize(10); // getSize() // 获得阵列数组的大小 $array->getSize(); // offsetExists(int $index) // 判断该索引是否存在值,返回boolean $array->offsetExists(3); // offsetGet(int $index) // 获得该索引对应的值 $array->offsetGet(3); // offsetSet(int $index, mixed $value) // 设置该索引对应的值 $array->offsetSet(6, 'value3'); // offsetUnset(int $index) // 删除该索引对应的值 $array->offsetUnset(6); // toArray() // 将阵列转化成php数组 // output: Array ( [0] => [1] => 2 [2] => [3] => value2 [4] => [5] => [6] => [7] => [8] => [9] => ) $php_array = $array->toArray(); // fromArray($php_array) // 将php数组转化成阵列
<?php $ar = new SplFixedArray(3); $ar[0] = 1; $ar[1] = 2; $ar[2] = 3; var_dump($ar->offsetExists(4));