Why is user_role_change_permissions() throwing an error? I want to change the permission of anonymous user to view content hits only for a blog section. I came across user_role_change_permissions(), but it is throwing an error when I use the following code.

 if ($user-&gt;uid == "0") {
   $custom_role = user_role_load_by_name('anonymous user'); 
   $custom_rid = $custom_role-&gt;rid; 
   $custom_permissions = array(
     'view content hits' =&gt; TRUE,
   );
  user_role_change_permissions($custom_rid, $custom_permissions);
 }


The error I get is the following:


  PDOException: SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'module' cannot be null: INSERT INTO {role_permission} (rid, permission, module) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2); Array ( [:db_insert_placeholder_0] => 1 [:db_insert_placeholder_1] => view content hits [:db_insert_placeholder_2] => ) in user_role_grant_permissions() (line 3154 of C:\xampp\htdocs\capacad\modules\user\user.module).





  Notice: Undefined index: view content hits in user_role_grant_permissions() (line 3152 of C:\xampp\htdocs\capacad\modules\user\user.module).


I tried also with user_role_grant_permissions(), but it doesn't work too.

How do I set a new permission for a role?
It should be like this:

if($user-&gt;uid == "0"){
  $custom_role = user_role_load_by_name('anonymous user'); 
  $custom_rid = $custom_role-&gt;rid; 
  $custom_permissions = array('view content hits');
  user_role_change_permissions($custom_rid, $custom_permissions);
 }


Here you have given 


  $custom_permissions = array(
      'view content hits' => TRUE,   );


TRUE should not be there.