Symfony\Component\Form\PropertyPath::readPropertyPath PHP Method

readPropertyPath() protected method

Recursive implementation of getValue()
protected readPropertyPath ( object | array &$objectOrArray, integer $currentIndex ) : mixed
$objectOrArray object | array The object or array to traverse
$currentIndex integer The current index in the property path
return mixed The value at the end of the path
    protected function readPropertyPath(&$objectOrArray, $currentIndex)
    {
        $property = $this->elements[$currentIndex];

        if (is_object($objectOrArray)) {
            $value = $this->readProperty($objectOrArray, $currentIndex);
        }
        // arrays need to be treated separately (due to PHP bug?)
        // http://bugs.php.net/bug.php?id=52133
        else {
            if (!array_key_exists($property, $objectOrArray)) {
                $objectOrArray[$property] = $currentIndex + 1 < $this->length ? array() : null;
            }

            $value =& $objectOrArray[$property];
        }

        ++$currentIndex;

        if ($currentIndex < $this->length) {
            return $this->readPropertyPath($value, $currentIndex);
        } else {
            return $value;
        }
    }