This API is part of the Hack Standard Library, not HHVM itself.

Returns a substring of length $length of the given string starting at the $offset

namespace HH\Lib\Str;

function slice(
  string $string,
  int $offset,
  ?int $length = NULL,
): string;

If no length is given, the slice will contain the rest of the string. If the length is zero, the empty string will be returned. If the offset is out-of-bounds, a ViolationException will be thrown.

Previously known as substr in PHP.


  • string $string
  • int $offset
  • ?int $length = NULL