On Fri, Oct 31, 2008 at 12:27 AM, David Metzler <metzlerd@metzlerd.com>wrote:

> It sounds like you're suggesting that $perm, a static variable within
> user_access() is being modified without user_access being called, but within
> a single page load.   That doesn't seem possible in PHP, unless there is a
> PHP bug.  Static variables are supposed to be local in scope to the
> functions that create them. To prove beyond a shadow of doubt, put a $debug
> statement in at the very beginning of the function user_access and another
> at the very end of the function.  (just before the return).  If what you're

This is exactly what I'm suggesting.  I put debug statements in user_access, node_content_access, and my OGUR function so that I would see every time they were accessed, and what was in them.

To briefly summarize, I have a role "GroupAdmin" which is dynamically added to the $user object.  It contains the "create story content" permission.

I issue the command to clear the $perm cache: user_access('ClearCache', NULL, TRUE)

This is followed by a module_invoke command (which, in turn will again call user_access):
module_invoke('node_content', 'access', 'create', 'story', $user)


The problem is that the $perm variable in the second user_access call should contain the values from the first user_access call, and it doesn't.  It is still set, as it should be, but the variables are different.  Here are the results of my debugging:


I noticed that even when my hook_init() clears the $perm variable:

The very next call to user_access does NOT contain the correct permissions:

Another test:


This is the page loaded:


http://mysite.com/node/ognodeadd?type=story&gids[]=24


User should be able to create story. This is what debug returns:

Installed devel module.  There are four user_access SQL queries that appear on this page:

1.16 1 user_access SELECT p.perm FROM role r INNER JOIN permission p ON p.rid = r.rid WHERE r.rid IN (2,8)
0.77 3 user_access SELECT p.perm FROM role r INNER JOIN permission p ON p.rid = r.rid WHERE r.rid IN (2,8,3,4,7)
0.76 3 user_access SELECT p.perm FROM role r INNER JOIN permission p ON p.rid = r.rid WHERE r.rid IN (2,8,3,4,7)
0.72 3 user_access SELECT p.perm FROM role r INNER JOIN permission p ON p.rid = r.rid WHERE r.rid IN (2,8,3,4,7)