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

Breadcrumb

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

function LazyGhostTrait::__get

File

vendor/symfony/var-exporter/LazyGhostTrait.php, line 121

Class

LazyGhostTrait

Namespace

Symfony\Component\VarExporter

Code

public function &__get($name) : mixed {
    $propertyScopes = Hydrator::$propertyScopes[$this::class] ??= Hydrator::getPropertyScopes($this::class);
    $scope = null;
    if ([
        $class,
        ,
        $readonlyScope,
    ] = $propertyScopes[$name] ?? null) {
        $scope = Registry::getScope($propertyScopes, $class, $name);
        $state = $this->lazyObjectState ?? null;
        if ($state && (null === $scope || isset($propertyScopes["\x00{$scope}\x00{$name}"]))) {
            if (LazyObjectState::STATUS_INITIALIZED_FULL === $state->status) {
                // Work around php/php-src#12695
                $property = null === $scope ? $name : "\x00{$scope}\x00{$name}";
                $property = $propertyScopes[$property][3] ?? (Hydrator::$propertyScopes[$this::class][$property][3] = new \ReflectionProperty($scope ?? $class, $name));
            }
            else {
                $property = null;
            }
            if ($property?->isInitialized($this) ?? LazyObjectState::STATUS_UNINITIALIZED_PARTIAL !== $state->initialize($this, $name, $readonlyScope ?? $scope)) {
                goto get_in_scope;
            }
        }
    }
    if ($parent = (Registry::$parentMethods[self::class] ??= Registry::getParentMethods(self::class))['get']) {
        if (2 === $parent) {
            return parent::__get($name);
        }
        $value = parent::__get($name);
        return $value;
    }
    if (null === $class) {
        $frame = debug_backtrace(\DEBUG_BACKTRACE_IGNORE_ARGS, 1)[0];
        trigger_error(\sprintf('Undefined property: %s::$%s in %s on line %s', $this::class, $name, $frame['file'], $frame['line']), \E_USER_NOTICE);
    }
    get_in_scope:
    try {
        if (null === $scope) {
            if (null === $readonlyScope) {
                return $this->{$name};
            }
            $value = $this->{$name};
            return $value;
        }
        $accessor = Registry::$classAccessors[$scope] ??= Registry::getClassAccessors($scope);
        return $accessor['get']($this, $name, null !== $readonlyScope);
    } 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) {
                $this->{$name} = [];
                return $this->{$name};
            }
            $accessor['set']($this, $name, []);
            return $accessor['get']($this, $name, null !== $readonlyScope);
        } catch (\Error) {
            if (preg_match('/^Cannot access uninitialized non-nullable property ([^ ]++) by reference$/', $e->getMessage(), $matches)) {
                throw new \Error('Typed property ' . $matches[1] . ' must not be accessed before initialization', $e->getCode(), $e->getPrevious());
            }
            throw $e;
        }
    }
}

API Navigation

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