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

Breadcrumb

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

function Context::addArray

1 call to Context::addArray()
Context::add in vendor/sebastian/recursion-context/src/Context.php
@psalm-template T

File

vendor/sebastian/recursion-context/src/Context.php, line 78

Class

Context

Namespace

SebastianBergmann\RecursionContext

Code

private function addArray(array &$array) : int {
    $key = $this->containsArray($array);
    if ($key !== false) {
        return $key;
    }
    $key = count($this->arrays);
    $this->arrays[] =& $array;
    if (!array_key_exists(PHP_INT_MAX, $array) && !array_key_exists(PHP_INT_MAX - 1, $array)) {
        $array[] = $key;
        $array[] = $this->objects;
    }
    else {
        
        /* Cover the improbable case, too.
         *
         * Note that array_slice() (used in containsArray()) will return the
         * last two values added, *not necessarily* the highest integer keys
         * in the array. Therefore, the order of these writes to $array is
         * important, but the actual keys used is not. */
        do {
            
            /** @noinspection PhpUnhandledExceptionInspection */
            $key = random_int(PHP_INT_MIN, PHP_INT_MAX);
        } while (array_key_exists($key, $array));
        $array[$key] = $key;
        do {
            
            /** @noinspection PhpUnhandledExceptionInspection */
            $key = random_int(PHP_INT_MIN, PHP_INT_MAX);
        } while (array_key_exists($key, $array));
        $array[$key] = $this->objects;
    }
    return $key;
}
RSS feed
Powered by Drupal