You are here

public static function Inspector::assertStringable in Drupal 9

Same name and namespace in other branches
  1. 8 core/lib/Drupal/Component/Assertion/Inspector.php \Drupal\Component\Assertion\Inspector::assertStringable()

Asserts argument is a string or an object castable to a string.

Use this instead of is_string() alone unless the argument being an object in any way will cause a problem.

Parameters

mixed $string: Variable to be examined

Return value

bool TRUE if $string is a string or an object castable to a string.

1 call to Inspector::assertStringable()
Inspector::assertAllStringable in core/lib/Drupal/Component/Assertion/Inspector.php
Asserts all members are strings or objects with magic __toString() method.

File

core/lib/Drupal/Component/Assertion/Inspector.php, line 115

Class

Inspector
Generic inspections for the assert() statement.

Namespace

Drupal\Component\Assertion

Code

public static function assertStringable($string) {
  return is_string($string) || is_object($string) && method_exists($string, '__toString');
}