Jump to content

Implications of final classes and final constants


NotionCommotion
 Share

Go to solution Solved by requinix,

Recommended Posts

Per the docs:

Quote

 

Class constants can be redefined by a child class. As of PHP 8.1.0, class constants cannot be redefined by a child class if it is defined as final.


 

Okay, guess that makes sense.  But what doesn't make sense (at least to me) is why I am getting the following error.  Can anyone explain why I am getting it?

final class DocumentExtension implements QueryCollectionExtensionInterface
{
    final private const EXEMPT_USER_ROLE = 'ROLE_TENANT_ADMIN';

    private function addWhere(QueryBuilder $queryBuilder, string $resourceClass): bool
    {
        if ($this->security->isGranted(self::EXEMPT_USER_ROLE)) {
            return false;
        }
    }
}

 

Quote

Fatal error: Private constant App\Doctrine\Extensions\DocumentExtension::EXEMPT_USER_ROLE cannot be final as it is not visible to other classes in /var/www/facdocs/api/src/Doctrine/Extensions/DocumentExtension.php on line 29

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.