/** * Clears/Resets a field by tag number * * @throws \Exception If trying to modify an unknown field * @param int $tag * @return \DrSlump\Protobuf\Message - Fluent interface */ public function _clear($tag) { $f = $this->_descriptor->getField($tag); if (!$f) { throw new \Exception('Unknown fields not supported'); } $name = $f->getName(); if (!$f->isExtension()) { $this->{$name} = $f->isRepeated() ? array() : NULL; } else { $this->_extensions[$name] = $f->isRepeated() ? array() : NULL; } return $this; }
public function offsetUnset($offset) { if (is_numeric($offset)) { $field = $this->_descriptor->getField($offset); if (!$field) { trigger_error("Protobuf message " . $this->_descriptor->getName() . " doesn't have any field with a tag number of {$offset}", E_USER_NOTICE); return; } if ($field->isExtension()) { $data =& $this->_extensions; } else { $data =& $this->_values; } if (isset($data[$field->name])) { unset($data[$field->name]); } } else { $this->clearExtension($offset); } }