laravel-acl icon indicating copy to clipboard operation
laravel-acl copied to clipboard

HasRole won't work on PHP 7.1

Open schleumer opened this issue 9 years ago • 3 comments

This piece of code will not work on PHP 7.1 and Laravel 5.3:

$laravel = app();
if (version_compare($laravel::VERSION, '5.3', '<')) {
    trait HasRole
    {
        use HasRoleImplementation {
            hasRole as is;
        }
    }
} else {
    trait HasRole
    {
        use HasRoleImplementation;
    }
}

Even with the if PHP will "validate" the code with the first trait, and so, will throw the exception:

hasRole($slug, $operator = NULL) should be compatible with Illuminate\Database\Eloquent\Model::is(Illuminate\Database\Eloquent\Model $model)

Just works if i remove the ìf`.

schleumer avatar Nov 06 '16 09:11 schleumer

hmm i have to test it locally, can

kodeine avatar Nov 06 '16 09:11 kodeine

Welp, not sure if this could be a PHP issue too, i'm using PHP 7.1.0 RC5. That change is not documented(PHP and it's way to document things not documenting).

schleumer avatar Nov 06 '16 09:11 schleumer

well

Illuminate\Database\Eloquent\Model::is(Illuminate\Database\Eloquent\Model $model)

method is() is reserved for Eloquent's implementation of it. I recommend to rename the method to something more explicit to avoid this conflict.

Maybe: hasRole()

affektde avatar Jan 09 '17 15:01 affektde