Answer the question
In order to leave comments, you need to log in
Is it correct to use constant arrays in php>=5.6?
It runs without errors, works correctly, but - phpstorm highlights the error (missing delimiter). Where is the mistake?
The line with the error, highlighting the errors highlighted in bold:
return (self::GROUP S[ $groupId] & $access ) === $access;
Code example:
class Roles
{
const
USER_OWNER = 1,
USER_ADMIN = 2,
USER_TESTER = 4;
const
ACCESS_VIEW = 1,
ACCESS_APPEND_ADMIN = 2,
ACCESS_APPEND_TESTER = 4,
ACCESS_CHANGE_KEY = 8;
const GROUPS = [
self::USER_OWNER =>
self::ACCESS_VIEW |
self::ACCESS_APPEND_ADMIN |
self::ACCESS_APPEND_TESTER |
self::ACCESS_CHANGE_KEY,
self::USER_ADMIN =>
self::ACCESS_VIEW |
self::ACCESS_APPEND_TESTER,
self::USER_TESTER =>
self::ACCESS_VIEW
];
public static function hasAccess($groupId, $access)
{
return (self::GROUPS[$groupId] & $access) === $access;
}
}
class Roles
{
const test = [1];
public static function returnConst()
{
return self::test[0];
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question