@
@
@xstudent2016-03-30 20:09:24
PHP
@xstudent, 2016-03-30 20:09:24

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;
    }
}

The same error (expected: semicolon) occurs on a simpler example:
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

1 answer(s)
M
maximw, 2016-03-31
_

Maybe that's the thing.
php.net/manual/en/migration70.incompatible.php
See section Changes to variable handling
In PHP7, the syntax for such constructs has changed. Perhaps the storm calls for disambiguation.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question