private function encodeObjectArray($object, array $options, callable $encode)
    {
        if (!\in_array((string) $options['object.format'], ['array', 'vars', 'iterate'], true)) {
            throw new \RuntimeException('Invalid object encoding format: ' . $options['object.format']);
        }

        $output = $encode($this->getObjectArray($object, $options['object.format']));

        if ($options['object.cast']) {
            $output = '(object)' . ($options['whitespace'] ? ' ' : '') . $output;
        }

        return $output;
    }