slice(0, 3); * The result is not cast, so the return value may be of type Stringy, * integer, boolean, etc. * * @param string $name * @param mixed[] $arguments * * @return Stringy * * @throws \BadMethodCallException */ public static function __callStatic($name, $arguments) { if (!static::$methodArgs) { $stringyClass = new ReflectionClass('Stringy\Stringy'); $methods = $stringyClass->getMethods(ReflectionMethod::IS_PUBLIC); foreach ($methods as $method) { $params = $method->getNumberOfParameters() + 2; static::$methodArgs[$method->name] = $params; } } if (!isset(static::$methodArgs[$name])) { throw new BadMethodCallException($name . ' is not a valid method'); } $numArgs = count($arguments); $str = ($numArgs) ? $arguments[0] : ''; if ($numArgs === static::$methodArgs[$name]) { $args = array_slice($arguments, 1, -1); $encoding = $arguments[$numArgs - 1]; } else { $args = array_slice($arguments, 1); $encoding = null; } $stringy = Stringy::create($str, $encoding); $result = call_user_func_array([$stringy, $name], $args); $cast = function($val) { if (is_object($val) && $val instanceof Stringy) { return (string) $val; } else { return $val; } }; return is_array($result) ? array_map($cast, $result) : $cast($result); } }