function UserSession::__get

Implements magic __get() method.

File

core/lib/Drupal/Core/Session/UserSession.php, line 216

Class

UserSession
An implementation of the user account interface for the global user.

Namespace

Drupal\Core\Session

Code

public function __get($name) : mixed {
  if ($name === 'name') {
    @trigger_error("Getting the name property is deprecated in drupal:11.3.0 and is removed from drupal:12.0.0. Use \\Drupal\\Core\\Session\\UserSession::getAccountName() instead. See https://www.drupal.org/node/3513856", E_USER_DEPRECATED);
    return $this->getAccountName();
  }
  $class = get_class($this);
  $properties = get_class_vars($class);
  if (\array_key_exists($name, $properties)) {
    throw new \LogicException("Cannot access protected property {$name} in " . $class);
  }
  return $this->{$name} ?? NULL;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.