public function dieOnCircularReference(&$stk, Project $p = null)
    {
        if ($this->checked) {
            return;
        }

        // elements can contain strings, FileSets, Reference, etc.
        foreach ($this->elements as $o) {
            if ($o instanceof Reference) {
                $o = $o->getReferencedObject($p);
            }

            if ($o instanceof DataType) {
                if (in_array($o, $stk, true)) {
                    throw $this->circularReference();
                } else {
                    $stk[] = $o;
                    $o->dieOnCircularReference($stk, $p);
                    array_pop($stk);
                }
            }
        }

        $this->checked = true;
    }