protected function getByRef($key, &$value)
    {
        if (!$this->checkRefs ||!is_string($value)) {
            return;
        }

        $this->checkRefs = false;
        $references = [$key];
        $key = $value;
        while ($this->isRef($key)) {
            if (in_array($key, $references)) {
                $this->checkRefs = true;
                $this->key = null;
                $references[] = $key;
                throw new RuntimeException(sprintf(
                    "Cyclic reference detected: %s",
                    implode(" ~~> ", $references)
                ));
            }
            $references[] = $key;
            $previous = $key;
            $key = $this->get($key, null, false);
        };
        $this->checkRefs = true;
        if (isset($previous)) {
            if ($this->exists($previous)) {
                $value = $key;
            } else {
                $this->key = null;
                $references[sizeof($references) - 1] .= " (missing key)";
                throw new RuntimeException(sprintf(
                    "Invalid reference detected: %s",
                    implode(" ~~> ", $references)
                ));
            }
        }
    }