Change record status: 
Project: 
Introduced in branch: 
11.3.x
Introduced in version: 
11.3.0
Description: 

The access of Twig templates to object methods can now allowed by the TwigAllowed attribute.
Example:

class AttributeAllowTestClass {

  #[\Drupal\Core\Template\Attribute\TwigAllowed]
  public function allowed(): string {
    return __METHOD__;
  }

  public function notAllowed(): string {
    return __METHOD__;
  }

  // Still allowed, but soon deprecated.
  public function getFoo(): string {
    return 'foo';
  }

}

Note that

Impacts: 
Module developers
Themers