src/TypedArray.php
public function offsetSet($k, $v)
	{
		if (null === $k || !array_key_exists($k, $this->_container)) {
			$v = (is_object($v) && get_class($v) === $this->_type) ? $v : new $this->_type($v);

			if (null === $k) {
				$this->_container[] = $v;
			}
			else {
				$this->_container[$k] = $v;
			}

			return;
		}

		if (is_a($this->_type, AtomicInterface::class, true)) {
			$this->_container[$k]->set($v);
			return;
		}

		if (is_a($this->_type, TypedAbstract::class, true)) {
			$this->_container[$k]->replace($v);
			return;
		}

		$this->_container[$k] = new $this->_type($v);
	}
public function offsetSet($k, $v)
	{
		if (null === $k || !array_key_exists($k, $this->_container)) {
			$v = (is_object($v) && get_class($v) === $this->_type) ? $v : new $this->_type($v);

			if (null === $k) {
				$this->_container[] = $v;
			}
			else {
				$this->_container[$k] = $v;
			}

			return;
		}

		if (is_a($this->_type, AtomicInterface::class, true)) {
			$this->_container[$k]->set($v);
			return;
		}

		if (is_a($this->_type, TypedAbstract::class, true)) {
			$this->_container[$k]->replace($v);
			return;
		}

		$this->_container[$k] = new $this->_type($v);
	}
Required by the ArrayAccess interface
Coerces input values to be the required type.

There are 5 basic conditions for $this->_type:
# $this->_type is null (accept any type and value, like a standard array);
# $this->_type is a scalar [bool, int, float, string];
# $this->_type is an array (check if input value is an object and has toArray);
# $this->_type is an object of type TypedAbstract (call replace());
# $this->_type is any other object.

There are 3 conditions involving $offset:
# $offset is null;
# $offset is set and does not exist (null);
# $offset is set and exists;

There are 4 conditions for handling $value:
# $value is null (replace current scalar values with null, reset non-scalars);
# $value is a scalar (cast);
# $value is a an array (check for toArray, or cast);
# $value is a an object (clone if the same as _type, otherwise new _type(value) );

@param string|int $k
@param mixed      $v