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

Breadcrumb

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

function HttpKernel::varToString

Returns a human-readable string for the specified variable.

1 call to HttpKernel::varToString()
HttpKernel::handleRaw in vendor/symfony/http-kernel/HttpKernel.php
Handles a request to convert it to a response.

File

vendor/symfony/http-kernel/HttpKernel.php, line 280

Class

HttpKernel
HttpKernel notifies events to convert a Request object to a Response one.

Namespace

Symfony\Component\HttpKernel

Code

private function varToString(mixed $var) : string {
    if (\is_object($var)) {
        return \sprintf('an object of type %s', $var::class);
    }
    if (\is_array($var)) {
        $a = [];
        foreach ($var as $k => $v) {
            $a[] = \sprintf('%s => ...', $k);
        }
        return \sprintf('an array ([%s])', mb_substr(implode(', ', $a), 0, 255));
    }
    if (\is_resource($var)) {
        return \sprintf('a resource (%s)', get_resource_type($var));
    }
    if (null === $var) {
        return 'null';
    }
    if (false === $var) {
        return 'a boolean value (false)';
    }
    if (true === $var) {
        return 'a boolean value (true)';
    }
    if (\is_string($var)) {
        return \sprintf('a string ("%s%s")', mb_substr($var, 0, 255), mb_strlen($var) > 255 ? '...' : '');
    }
    if (is_numeric($var)) {
        return \sprintf('a number (%s)', (string) $var);
    }
    return (string) $var;
}

API Navigation

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