/** * Converts / casts a value to a IString object. * * @param mixed $val The value to convert / cast * @param bool $nullAsEmpty Handle (null) as empty string or not. * @param bool $mutable String should be mutable or not. * * @return IString|null The (new) string object or (null) if $val is also (null) AND * $nullAsEmpty has the value (false). */ public static final function asString($val, bool $nullAsEmpty = true, bool $mutable = false) { if (null === $val) { if (!$nullAsEmpty) { return null; } } if (!$val instanceof IString) { $val = new self($val); } if ($mutable) { return $val->asMutable(); } return $val; }