Safely (atomically) increments the value of the specified field by an arbitrary value. Defaults to `1` if no value is specified. Throws an exception if the specified field is non-numeric.

Parameters

  • string $field The name of the field to be incrememnted.
  • integer|string $value The value to increment the field by. Defaults to `1` if this parameter is not specified.

Returns

integer Returns the current value of `$field`, based on the value retrieved from the data source when the entity was loaded, plus any increments applied. Note that it may not reflect the most current value in the persistent backend data source.

Source

						public function increment($field, $value = 1) {
		if (!isset($this->_increment[$field])) {
			$this->_increment[$field] = 0;
		}
		$this->_increment[$field] += $value;

		if (!is_numeric($this->_updated[$field])) {
			throw new UnexpectedValueException("Field `{$field}` cannot be incremented.");
		}
		return $this->_updated[$field] += $value;
	}