private function getDataReference($item) {
    if ($this->isASleepingReference) {
      $this->referenceWake();
    }
    if ((is_a($item, '\Nymph\Entity') || is_a($item, '\SciActive\HookOverride'))
        && is_callable([$item, 'toReference'])) {
      // Convert entities to references.
      return $item->toReference();
    } elseif (is_array($item)) {
      // Recurse into lower arrays.
      return array_map([$this, 'getDataReference'], $item);
    } elseif (is_object($item)) {
      foreach ($item as &$curProperty) {
        $curProperty = $this->getDataReference($curProperty);
      }
      unset($curProperty);
    }
    // Not an entity or array, just return it.
    return $item;
  }