function MemoryStorage::setIfNotExists

Same name in other branches
  1. 9 core/lib/Drupal/Core/KeyValueStore/MemoryStorage.php \Drupal\Core\KeyValueStore\MemoryStorage::setIfNotExists()
  2. 8.9.x core/lib/Drupal/Core/KeyValueStore/MemoryStorage.php \Drupal\Core\KeyValueStore\MemoryStorage::setIfNotExists()
  3. 11.x core/lib/Drupal/Core/KeyValueStore/MemoryStorage.php \Drupal\Core\KeyValueStore\MemoryStorage::setIfNotExists()

Overrides KeyValueStoreInterface::setIfNotExists

File

core/lib/Drupal/Core/KeyValueStore/MemoryStorage.php, line 55

Class

MemoryStorage
Defines a default key/value store implementation.

Namespace

Drupal\Core\KeyValueStore

Code

public function setIfNotExists($key, $value) {
    if (!isset($this->data[$key])) {
        $this->data[$key] = $value;
        return TRUE;
    }
    return FALSE;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.