You are here

public function Random::object in Drupal 8

Same name and namespace in other branches
  1. 9 core/lib/Drupal/Component/Utility/Random.php \Drupal\Component\Utility\Random::object()
  2. 10 core/lib/Drupal/Component/Utility/Random.php \Drupal\Component\Utility\Random::object()

Generates a random PHP object.

Parameters

int $size: The number of random keys to add to the object.

Return value

object The generated object, with the specified number of random keys. Each key has a random string value.

File

core/lib/Drupal/Component/Utility/Random.php, line 171

Class

Random
Defines a utility class for creating random data.

Namespace

Drupal\Component\Utility

Code

public function object($size = 4) {
  $object = new \stdClass();
  for ($i = 0; $i < $size; $i++) {
    $random_key = $this
      ->name();
    $random_value = $this
      ->string();
    $object->{$random_key} = $random_value;
  }
  return $object;
}