$structure->getters VS normal getters? And cache?

Robert9

Well-known member
When we use $structure->getters instead a normal getter?
When we use a cache for $structure->getters?
 
When we use $structure->getters instead a normal getter?
I don't really understand this question, but i'll try to anser it anyway:

Let's take a lokk at XF\Entity\User which has a getter is_user_admin.

So if you want to check if a user is a super admin you can do
PHP:
if ($user->getIsSuperAdmin())

or

PHP:
if ($user->is_super_admin)

It wouldn't matter which one you use if the getter was uncached, both would yield the exact same result (but using the virtual property might be more convenient)

When we use a cache for $structure->getters?
When it is okay to get cached results.

Let's take the user entity as an example again
PHP:
$user = \XF::finder('XF:User', $userIdOfASuperAdmin);

if ($user->is_super_admin)
{
// will be executed when
}

$user->is_admin = false;
if ($user->is_super_admin)
{
// will still be executed due to cached getter result
}

if ($user->getIsSuperAdmin())
{
// will never be executed
}
 
Thank you.

If I want to use cached values, I use structure getters.

If I don't need cached values, I can use both ways.

Correct?
 
Top Bottom