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

Breadcrumb

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

function RepeatedField::offsetSet

Assign the element at the given index.

This will also be called for: $arr []= $ele and $arr[0] = ele

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

Parameters

int|null $offset The index of the element to be assigned.:

mixed $value The element to be assigned.:

Return value

void

Throws

\ErrorException Invalid type for index.

\ErrorException Non-existing index.

\ErrorException Incorrect type of the element.

File

vendor/google/protobuf/src/Google/Protobuf/Internal/RepeatedField.php, line 122

Class

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

Namespace

Google\Protobuf\Internal

Code

public function offsetSet($offset, $value) {
    switch ($this->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::BYTES:
            GPBUtil::checkString($value, false);
            break;
        case GPBType::STRING:
            GPBUtil::checkString($value, true);
            break;
        case GPBType::MESSAGE:
            if (is_null($value)) {
                throw new \TypeError("RepeatedField element cannot be null.");
            }
            GPBUtil::checkMessage($value, $this->klass);
            break;
        default:
            break;
    }
    if (is_null($offset)) {
        $this->container[] = $value;
    }
    else {
        $count = count($this->container);
        if (!is_numeric($offset) || $offset < 0 || $offset >= $count) {
            trigger_error("Cannot modify element at the given index", E_USER_ERROR);
            return;
        }
        $this->container[$offset] = $value;
    }
}

API Navigation

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