Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. LazyProxyTrait.php

function LazyProxyTrait::__get

File

vendor/symfony/var-exporter/LazyProxyTrait.php, line 103

Class

LazyProxyTrait

Namespace

Symfony\Component\VarExporter

Code

public function &__get($name) : mixed {
    $propertyScopes = Hydrator::$propertyScopes[$this::class] ??= Hydrator::getPropertyScopes($this::class);
    $scope = null;
    $instance = $this;
    if ([
        $class,
        ,
        $readonlyScope,
    ] = $propertyScopes[$name] ?? null) {
        $scope = Registry::getScope($propertyScopes, $class, $name);
        if (null === $scope || isset($propertyScopes["\x00{$scope}\x00{$name}"])) {
            if ($state = $this->lazyObjectState ?? null) {
                $instance = $state->realInstance ??= ($state->initializer)();
            }
            $parent = 2;
            goto get_in_scope;
        }
    }
    $parent = (Registry::$parentMethods[self::class] ??= Registry::getParentMethods(self::class))['get'];
    if ($state = $this->lazyObjectState ?? null) {
        $instance = $state->realInstance ??= ($state->initializer)();
    }
    else {
        if (2 === $parent) {
            return parent::__get($name);
        }
        $value = parent::__get($name);
        return $value;
    }
    if (!$parent && null === $class && !\array_key_exists($name, (array) $instance)) {
        $frame = debug_backtrace(\DEBUG_BACKTRACE_IGNORE_ARGS, 1)[0];
        trigger_error(\sprintf('Undefined property: %s::$%s in %s on line %s', $instance::class, $name, $frame['file'], $frame['line']), \E_USER_NOTICE);
    }
    get_in_scope:
    try {
        if (null === $scope) {
            if (null === $readonlyScope && 1 !== $parent) {
                return $instance->{$name};
            }
            $value = $instance->{$name};
            return $value;
        }
        $accessor = Registry::$classAccessors[$scope] ??= Registry::getClassAccessors($scope);
        return $accessor['get']($instance, $name, null !== $readonlyScope || 1 === $parent);
    } catch (\Error $e) {
        if (\Error::class !== $e::class || !str_starts_with($e->getMessage(), 'Cannot access uninitialized non-nullable property')) {
            throw $e;
        }
        try {
            if (null === $scope) {
                $instance->{$name} = [];
                return $instance->{$name};
            }
            $accessor['set']($instance, $name, []);
            return $accessor['get']($instance, $name, null !== $readonlyScope || 1 === $parent);
        } catch (\Error) {
            throw $e;
        }
    }
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal