$user versus $kirby->user() ?!

I tried to display username and userrole after login with

echo $user->username()
echo $user->role()

because that is what is suggested in the reference and what I saw in many articles. But that didn’t work.

I ended up using

$user = $kirby->user();

first. Then it worked.

I found this article in the forum, but it didn’t help:
$site->users() became $kirby->users()?

Now I’m irritated: is there a mistake in the reference or is using $user (as an object originating from kirby) restricted to a special usecase?

$user is just a reference to the object that is supposed to be used with the methods. There is no global $user variable, so you have to first define the $user variable, as explained in the $user reference a bit further down the page: https://getkirby.com/docs/reference/objects/user#how-to-create-a-user-object

The same is true for all other objects, apart from the globally accessible $site, $page, $pages and $kirby variables in templates and snippets (only).

oooohhhh …
sorry for taking your time …

Wer lesen kann, ist klar im Vorteil …

Thank you!