Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. LazyString.php

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\String

Code

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;
    }
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal