Back to AbstractMenu class

Method __get

public \Joomla\CMS\User\User|null
__get
(mixed $propName)
Magic getter for the user object. Returns the injected one if any, or the current one if none.
Parameters
  • string $propName Name of the missing or protected property.
Returns
  • \Joomla\CMS\User\User|null
Since
  • 3.9.26
Class: AbstractMenu
Project: Joomla

Method __get - Source code

/**
 * Magic getter for the user object. Returns the injected
 * one if any, or the current one if none.
 *
 * Using a magic getter to preserve B/C when we stopped storing the user object upon construction of the menu object.
 * As the user property is not initialized anymore, this getter ensures any class extending
 * this one can still use $instance->user and get a proper value.
 *
 * @param   string  $propName  Name of the missing or protected property.
 *
 * @return User|null
 *
 * @since 3.9.26
 */
public function __get($propName)
{
    if ($propName === 'user') {
        return empty($this->storedUser) ? Factory::getUser() : $this->storedUser;
    }
    return null;
}