public function key($key, $value = null, $setOnlyIfDoesntExist = false)
    {
        $key = StdObjectWrapper::toString($key);
        $array = $this->val();

        if ($setOnlyIfDoesntExist && !$this->keyExists($key)) {
            $array[$key] = $value;
            $this->val($array);

            return $value;
        } else {
            if (!$setOnlyIfDoesntExist && !$this->isNull($value)) {
                $array[$key] = $value;
                $this->val($array);

                return $this;
            }
        }

        if (!isset($array[$key])) {
            return $value;
        }

        return $array[$key];
    }