Alright, since my previous answer was deleted.. here's another go.
Your problem is the type-safe comparison you do here:
if($permissions[$key] === true) {
return true;
}
Your array is filled from a json object {"moderator": 1}
, which translates to array('moderator' => 1)
in php. You are comparing a boolean true
with an integer 1
using a type-safe comparison. That will fail because the types do not match. See http://php.net/manual/en/language.operators.comparison.php for more detail.
You can remedy this by either using type-unsafe comparisons or by converting your $permissions
to booleans.
if ((bool)$permissions[$key] === true) // Both are now of type boolean and will be compared.
or
if ($permissions[$key] == true) // Will compare 1 and TRUE, which will result in TRUE.