Stringy\Stringy::offsetGet PHP 메소드

offsetGet() 공개 메소드

Returns the character at the given index. Offsets may be negative to count from the last character in the string. Implements part of the ArrayAccess interface, and throws an OutOfBoundsException if the index does not exist.
public offsetGet ( mixed $offset ) : mixed
$offset mixed The index from which to retrieve the char
리턴 mixed The character at the specified index
    public function offsetGet($offset)
    {
        $offset = (int) $offset;
        $length = $this->length();
        if ($offset >= 0 && $length <= $offset || $length < abs($offset)) {
            throw new OutOfBoundsException('No character exists at the index');
        }
        return \mb_substr($this->str, $offset, 1, $this->encoding);
    }