function LazyString::__toString
2 calls to LazyString::__toString()
- LazyString::jsonSerialize in vendor/
symfony/ string/ LazyString.php - LazyString::__sleep in vendor/
symfony/ string/ LazyString.php
File
-
vendor/
symfony/ string/ LazyString.php, line 82
Class
- LazyString
- A string whose value is computed lazily by a callback.
Namespace
Symfony\Component\StringCode
public function __toString() : string {
if (\is_string($this->value)) {
return $this->value;
}
try {
return $this->value = ($this->value)();
} catch (\Throwable $e) {
if (\TypeError::class === $e::class && __FILE__ === $e->getFile()) {
$type = explode(', ', $e->getMessage());
$type = substr(array_pop($type), 0, -\strlen(' returned'));
$r = new \ReflectionFunction($this->value);
$callback = $r->getStaticVariables()['callback'];
$e = new \TypeError(\sprintf('Return value of %s() passed to %s::fromCallable() must be of the type string, %s returned.', $callback, static::class, $type));
}
throw $e;
}
}