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