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

Breadcrumb

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

function Compiler::repr

Returns a PHP representation of a given value.

Return value

$this

File

vendor/twig/twig/src/Compiler.php, line 156

Class

Compiler
@author Fabien Potencier <fabien@symfony.com>

Namespace

Twig

Code

public function repr($value) {
    if (\is_int($value) || \is_float($value)) {
        if (false !== ($locale = setlocale(\LC_NUMERIC, '0'))) {
            setlocale(\LC_NUMERIC, 'C');
        }
        $this->raw(var_export($value, true));
        if (false !== $locale) {
            setlocale(\LC_NUMERIC, $locale);
        }
    }
    elseif (null === $value) {
        $this->raw('null');
    }
    elseif (\is_bool($value)) {
        $this->raw($value ? 'true' : 'false');
    }
    elseif (\is_array($value)) {
        $this->raw('array(');
        $first = true;
        foreach ($value as $key => $v) {
            if (!$first) {
                $this->raw(', ');
            }
            $first = false;
            $this->repr($key);
            $this->raw(' => ');
            $this->repr($v);
        }
        $this->raw(')');
    }
    else {
        $this->string($value);
    }
    return $this;
}
RSS feed
Powered by Drupal