NotionCommotion Posted September 19, 2022 Share Posted September 19, 2022 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 Quote Link to comment https://forums.phpfreaks.com/topic/315345-implications-of-final-classes-and-final-constants/ Share on other sites More sharing options...
Solution requinix Posted September 19, 2022 Solution Share Posted September 19, 2022 private + final doesn't make sense: if it's private then nothing can override it anyway. Just make it private. Quote Link to comment https://forums.phpfreaks.com/topic/315345-implications-of-final-classes-and-final-constants/#findComment-1600756 Share on other sites More sharing options...
NotionCommotion Posted September 19, 2022 Author Share Posted September 19, 2022 Agreed it didn't make sense. Just didn't know whether I was missing something else. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/315345-implications-of-final-classes-and-final-constants/#findComment-1600758 Share on other sites More sharing options...
requinix Posted September 19, 2022 Share Posted September 19, 2022 It's one of those things that isn't harmful per se - it's redundant, really - but if someone wrote it then they could be making a mistake in some other sort of way. Quote Link to comment https://forums.phpfreaks.com/topic/315345-implications-of-final-classes-and-final-constants/#findComment-1600760 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.