예제 #1
0
 /**
  * @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);
 }
예제 #2
0
 protected function extract($format, $offset, $length)
 {
     $encoded = '';
     for ($i = 0; $i < $length; $i++) {
         $encoded .= $this->buffer->offsetGet($offset + $i);
     }
     if ($format == 'N' && PHP_INT_SIZE <= 4) {
         list(, $h, $l) = unpack('n*', $encoded);
         $result = $l + $h * 0x10000;
     } else {
         if ($format == 'V' && PHP_INT_SIZE <= 4) {
             list(, $h, $l) = unpack('v*', $encoded);
             $result = $h + $l * 0x10000;
         } else {
             list(, $result) = unpack($format, $encoded);
         }
     }
     return $result;
 }
<?php

$array = new SplFixedArray(5);
$array[0] = 'a';
$a = $array->offsetGet();
if (is_null($a)) {
    echo 'PASS';
}
 public function offsetGet($n)
 {
     echo "A::offsetGet\n";
     return parent::offsetGet($n);
 }
예제 #5
0
// 获得当前节点
$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数组转化成阵列
// output: SplFixedArray Object ( [0] => [1] => 2 [2] => [3] => value2 [4] => [5] => [6] => [7] => [8] => [9] => )
$spl_array = SplFixedArray::fromArray($php_array);