1

Can't use function return value in write context.

All the search result responses say its something to do with the empty function, but I'm not using that?

foreach ($permission as explode(',', $permissionString)) { // line 44
    if ($this->hasPermission($permission))
        $count++;
}
1
  • 4
    Your variables in the foreach-statement is in the wrong order. It should be: foreach (explode(',', $permissionString) as $permission). As stated in the documentation: foreach (array_expression as $value). Commented Sep 26, 2017 at 20:24

1 Answer 1

2

In a foreach the expression on the left of the as should be the array that you want to iterate through, and the expression on the right is a variable that gets overwritten with the value of each element inside the array.

The reason that you get an error is because php is trying to write an element of $permission into explode(',', $permissionString), but this returns an error because explode(',', $permissionString) is a function call, not a variable, and only variables can be written to.

To fix this, try reversing the order of the as, like this:

foreach (explode(',', $permissionString) as $permission) {
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.