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

Breadcrumb

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

function MapField::offsetSet

Assign the element at the given key.

This will also be called for: $arr[$key] = $value

@todo need to add return type void (require update php version to 7.1)

Parameters

int|string $key The key of the element to be fetched.:

object $value The element to be assigned.:

Return value

void

Throws

\ErrorException Invalid type for key.

\ErrorException Invalid type for value.

\ErrorException Non-existing key.

File

vendor/google/protobuf/src/Google/Protobuf/Internal/MapField.php, line 136

Class

MapField
MapField is used by generated protocol message classes to manipulate map fields. It can be used like native PHP array.

Namespace

Google\Protobuf\Internal

Code

public function offsetSet($key, $value) {
    $this->checkKey($this->key_type, $key);
    switch ($this->value_type) {
        case GPBType::SFIXED32:
        case GPBType::SINT32:
        case GPBType::INT32:
        case GPBType::ENUM:
            GPBUtil::checkInt32($value);
            break;
        case GPBType::FIXED32:
        case GPBType::UINT32:
            GPBUtil::checkUint32($value);
            break;
        case GPBType::SFIXED64:
        case GPBType::SINT64:
        case GPBType::INT64:
            GPBUtil::checkInt64($value);
            break;
        case GPBType::FIXED64:
        case GPBType::UINT64:
            GPBUtil::checkUint64($value);
            break;
        case GPBType::FLOAT:
            GPBUtil::checkFloat($value);
            break;
        case GPBType::DOUBLE:
            GPBUtil::checkDouble($value);
            break;
        case GPBType::BOOL:
            GPBUtil::checkBool($value);
            break;
        case GPBType::STRING:
            GPBUtil::checkString($value, true);
            break;
        case GPBType::MESSAGE:
            if (is_null($value)) {
                trigger_error("Map element cannot be null.", E_USER_ERROR);
            }
            GPBUtil::checkMessage($value, $this->klass);
            break;
        default:
            break;
    }
    $this->container[$key] = $value;
}

API Navigation

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