<html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">
<div>I downloaded and looked at the code for user_access and I have one idea. I've had some problem intializing static structures to arrays or objects in certain versions of php. Try changing the definition of $perm as follows: </div><div><br></div><div>static $perm = ''; </div><div>if (!$perm) $perm = array(); </div><div><br></div><div>See if that changes the caching behavior in your php rev. </div><div><br></div><div>Dave</div><div><br></div><div> <div><div><div>On Oct 31, 2008, at 11:38 AM, Ron Parker wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0; "><div style="font-family: Arial; font-size: 10pt; color: rgb(0, 0, 0); ">On<span class="Apple-converted-space"> </span><span class="Object" id="OBJ_PREFIX_DWT499"><span class="Object" id="OBJ_PREFIX_DWT502">Fri</span></span>,<span class="Apple-converted-space"> </span><span class="Object" id="OBJ_PREFIX_DWT500"><span class="Object" id="OBJ_PREFIX_DWT503">Oct 31, 2008</span></span><span class="Apple-converted-space"> </span>at 12:27 AM, David Metzler <<span class="Object" id="OBJ_PREFIX_DWT501"><span class="Object" id="OBJ_PREFIX_DWT504"><a href="mailto:metzlerd@metzlerd.com">metzlerd@metzlerd.com</a></span></span>>wrote:<br><br>> It sounds like you're suggesting that $perm, a static variable within<br>> user_access() is being modified without user_access being called, but within<br>> a single page load. That doesn't seem possible in PHP, unless there is a<br>> PHP bug. Static variables are supposed to be local in scope to the<br>> functions that create them. To prove beyond a shadow of doubt, put a $debug<br>> statement in at the very beginning of the function user_access and another<br>> at the very end of the function. (just before the return). If what you're<br><br>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.<br><br>To briefly summarize, I have a role "GroupAdmin" which is dynamically added to the $user object. It contains the "create story content" permission.<br><br>I issue the command to clear the $perm cache:<span class="Apple-converted-space"> </span><strong>user_access('ClearCache', NULL, TRUE)<br><span style="font-weight: bold; "><span style="font-weight: bold; "></span></span></strong><br>This is followed by a module_invoke command (which, in turn will again call user_access):<br><strong>module_invoke('node_content', 'access', 'create', 'story', $user)</strong><br><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><br></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">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:<br></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><br></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">I noticed that even when my hook_init() clears the $perm variable:</div><ul><li><strong>user_access('', NULL, TRUE)</strong></li><li>ogur roles loaded into user object (hook_init)</li><li>user_access | string =</li><li>user_access |<span class="Apple-converted-space"> </span><strong>static $perm is NOT already set</strong></li><li>user_access | $perm set for uid 3 (test01)</li><li>user_access | string = | $perm values = 0,1,2,0,1,2,4,5,7,8,9,10,4,5,6,7,8,9,10,0,0,1,2,3,4</li><li>user_access | roles returned: (authenticated user,Devel,Group Member,Group Contributor,Group Admin)</li><li>user_access | permissions returned: (access comments,access content,view uploaded files,view advanced help index,view advanced help popup,view advanced help topic,post comments,post comments without approval,search content,use advanced search,subscribe to newsletters,view links in block,create page content,create story content,delete own page content,delete own story content,edit own page content,edit own story content,upload files,configure member roles,access devel information,display source code,execute php code,switch users,view devel_node_access information)</li></ul><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">The very next call to user_access does NOT contain the correct permissions:</div><ul><li><strong>user_access('access content')</strong></li><li>user_access | string =<span class="Apple-converted-space"> </span><strong>access content</strong><span class="Apple-converted-space"> </span>| $perm values = 0,1,2,3,4,5,6,7,8,9,10,0,1,2,3,4 (<span style="font-style: italic; ">note that all the permmissions from above are NOT here - the only ones missing are those granted by the dynamically assigned roles</span>)<br></li><li>user_access |<span class="Apple-converted-space"> </span><strong>static $perm is already set</strong></li><li>user_access | roles returned: (authenticated user,Devel,Group Member,Group Contributor,Group Admin)</li><li>user_access | permissions returned: (view advanced help index,view advanced help popup,view advanced help topic,access comments,post comments,post comments without approval,access content,search content,use advanced search,subscribe to newsletters,view links in block,access devel information,display source code,execute php code,switch users,view devel_node_access information)</li></ul><div style="font-weight: bold; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">Another test:</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><br></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">This is the page loaded:</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><br></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><a href="http://mysite.com/node/ognodeadd?type=story&gids[]=24">http://mysite.com/node/ognodeadd?type=story&gids[]=24</a></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><br></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">User should be able to create story. This is what debug returns:</div><ul><li>ogur roles loaded into user object (ognodeadd)</li><li>ogur | ognodeadd roles returned: (authenticated user,Devel,Group Member,Group Contributor,<span style="font-weight: bold; ">Group Admin</span>) <span class="Apple-converted-space"> </span><em>These are the correct roles for this user in this group.</em></li><li>ogur | module to call = node_content | type =<span class="Apple-converted-space"> </span><strong>story</strong></li><li>ogur | Preparing to call<span class="Apple-converted-space"> </span><strong>module_invoke</strong></li><li>ogur | Calling<span class="Apple-converted-space"> </span><strong>user_access('ClearCache', NULL, TRUE)</strong></li><li>user_access | string =<span class="Apple-converted-space"> </span><strong>ClearCache</strong></li><li>user_access |<span class="Apple-converted-space"> </span><strong>static $perm is NOT already set</strong></li><li>user_access | $perm set for uid 3 (test01)</li><li>user_access | string =<span class="Apple-converted-space"> </span><strong>ClearCache</strong><span class="Apple-converted-space"> </span>| $perm values = 0,1,2,0,1,2,4,5,7,8,9,10,4,5,6,7,8,9,10,0,0,1,2,3,4</li><li>user_access | roles returned: (authenticated user,Devel,Group Member,Group Contributor,Group Admin) <span class="Apple-converted-space"> </span><em>This is correct.</em></li><li>user_access | permissions returned: (access comments,access content,view uploaded files,view advanced help index,view advanced help popup,view advanced help topic,post comments,post comments without approval,search content,use advanced search,subscribe to newsletters,view links in block,<strong>create page content,create story content,delete own page content,delete own story content,edit own page content,edit own story content,upload files</strong>,configure member roles,access devel information,display source code,execute php code,switch users,view devel_node_access information)<br> <span class="Apple-converted-space"> </span><br><em>The above are the permissions that $perm should have the next time user_access is ran. It will run again when module_invoke() is called. Below is what comes back the very next time user_access is called.<br></em></li></ul><ul><li>ogur | Calling<span class="Apple-converted-space"> </span><strong>module_invoke('node_content', 'access', 'create', 'story', $user)</strong></li><li>node_content_access | type = story | op = create</li><li>node_content_access | roles returned: (authenticated user,Devel,Group Member,Group Contributor,Group Admin)</li><li>user_access | string =<span class="Apple-converted-space"> </span><strong>create story content</strong><span class="Apple-converted-space"> </span>| $perm values = 0,1,2,3,4,5,6,7,8,9,10,0,1,2,3,4</li><li>user_access |<span class="Apple-converted-space"> </span><strong>static $perm is already set</strong></li><li>user_access | roles returned: (authenticated user,Devel,Group Member,Group Contributor,<span style="font-weight: bold; ">Group Admin</span>)<span class="Apple-converted-space"> </span><em>This is correct.</em></li><li>user_access | permissions returned: (view advanced help index,view advanced help popup,view advanced help topic,access comments,post comments,post comments without approval,access content,search content,use advanced search,subscribe to newsletters,view links in block,access devel information,display source code,execute php code,switch users,view devel_node_access information)<div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><em>Note that the "Group Admin" role permissions are not included here. They should be the same as from<span class="Apple-converted-space"> </span></em><em>from the ClearCache user_access command above.</em><em><span class="Apple-converted-space"> </span>It appears that the above permissions have been cached somewhere else.<span class="Apple-converted-space"> </span><br></em></div></li><li>ogur |<span class="Apple-converted-space"> </span><strong>module_invoke</strong><span class="Apple-converted-space"> </span>called</li><li>ogur | ognodeadd roles returned: (authenticated user,Devel,Group Member,Group Contributor,Group Admin)</li><li>ogur | module_invoke access returns<span class="Apple-converted-space"> </span><strong>false</strong><br><em>Access should be<span class="Apple-converted-space"> </span><strong>true</strong><span class="Apple-converted-space"> </span>here.</em></li></ul><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">Installed devel module. There are four<span class="Apple-converted-space"> </span><strong>user_access</strong><span class="Apple-converted-space"> </span>SQL queries that appear on this page:<br></div><table class="sticky-enabled sticky-table" border="0"><tbody><tr class="even"><td>1.16</td><td>1</td><td><a href="http://api.drupal.org/api/6/function/user_access">user_access</a></td><td>SELECT p.perm FROM role r INNER JOIN permission p ON p.rid = r.rid WHERE r.rid IN (2,8)</td></tr></tbody></table><table class="sticky-enabled sticky-table" border="0"><tbody><tr class="odd"><td>0.77</td><td class="marker">3</td><td><a href="http://api.drupal.org/api/6/function/user_access">user_access</a></td><td>SELECT p.perm FROM role r INNER JOIN permission p ON p.rid = r.rid WHERE r.rid IN (2,8,3,4,7)</td></tr></tbody></table><table class="sticky-enabled sticky-table" border="0"><tbody><tr class="odd"><td>0.76</td><td class="marker">3</td><td><a href="http://api.drupal.org/api/6/function/user_access">user_access</a></td><td>SELECT p.perm FROM role r INNER JOIN permission p ON p.rid = r.rid WHERE r.rid IN (2,8,3,4,7)</td></tr></tbody></table><table class="sticky-enabled sticky-table" border="0"><tbody><tr class="odd"><td>0.72</td><td class="marker">3</td><td><a href="http://api.drupal.org/api/6/function/user_access">user_access</a></td><td>SELECT p.perm FROM role r INNER JOIN permission p ON p.rid = r.rid WHERE r.rid IN (2,8,3,4,7)</td></tr></tbody></table><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "> </p><br><br><br><br><br><br></div></span></blockquote></div><br></div></div></body></html>