According to the documentation:

If you implement this hook and see an error like 'Call to undefined function', it is likely that you are depending on the presence of a module which has not been loaded yet. It is not loaded because Drupal is still in bootstrap mode.

So... I am seeing that error, frequently. The following patch makes it go away, but I'm not sure that it's the correct fix:

CommentFileSizeAuthor
#30 rules_exit.patch532 bytesfago
#21 user_access-1019646-19.patch490 bytesAnonymous (not verified)
#5 rules.patch1.28 KBpillarsdotnet
#3 rules_user_function_fix.patch1.24 KBfago
rules_exit.patch677 bytespillarsdotnet

Comments

geerlingguy’s picture

Same here. I'm hitting this problem on most pages on my site.

Fatal error: Call to undefined function user_access() in /path/to/rules.module on line 916

Offending code:

/**
 * Implements hook_exit().
 */
function rules_exit() {
  if (variable_get('rules_debug', FALSE) || (user_access('administer rules') && RulesLog::logger()->hasErrors())) {
    if ($log = RulesLog::logger()->render()) {
      // Keep the log in the session so we can show it on the next page.
      $_SESSION['rules_debug'][] = $log;
    }
  }
}

Also, I have error reporting set to show no errors on screen, and this error message shows up at the bottom of my pages, after the closing </html> tag. See: http://www.midwesternmac.com/

geerlingguy’s picture

Status: Active » Needs review

Setting to needs review. Patch fixes the main issue, but I don't know if that's the ideal solution.

fago’s picture

StatusFileSize
new1.24 KB

The solution is fine, though I think this can check should be improved anyway. Does the attached patch fix it for your too?

pillarsdotnet’s picture

Status: Needs review » Reviewed & tested by the community

I can confirm that the patch in #3 also makes the error go away.

pillarsdotnet’s picture

StatusFileSize
new1.28 KB

Re-rolled patch to correct for some fuzz.

fago’s picture

Status: Reviewed & tested by the community » Fixed

thanks, committed.

enrikito’s picture

7.x-2.0-alpha5

PHP Fatal error: Call to undefined function user_access() in rules/rules.module on line 1006

"on line 1006"

enrikito’s picture

thanks

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

SilviuChingaru’s picture

Title: I'm seeing the same thing » PHP Fatal error: Call to undefined function user_access() in rules/rules.module on line 916

I think there is the same error in latest version. This is the output in my error_log:
[Wed Feb 08 22:28:03 2012] [error] [client 89.137.*.*] PHP Fatal error: Call to undefined function user_access() in /drupal/sites/modules/rules/rules.module on line 1084, referer: http://everypage_of_my_site as anonymouse user

Curent config:
D 7.12
Rules 7.x-2.0

Debug mode on

alexandersluiter’s picture

Title: PHP Fatal error: Call to undefined function user_access() in rules/rules.module on line 916 » I'm seeing the same thing
Version: 7.x-2.x-dev » 7.x-2.0
Status: Closed (fixed) » Active

I'm seeing the same thing. I'll see if I can find a fix unless someone else comes up with something before me. It's only when I have "cache blocks and/or cache pages anon visitors" on in the performance section. I'd really like to use Drupal's caching methods due to the amount of traffic on the site and load times. I've found that I'm seeing it every time someone hits the home page after they've been to the site...weird...I know.

My setup:

Drupal 7.12
Rules 7.20
A Bunch of other modules...

Web Server:
Apache 2
PHP 5.3.10 (cli)
MySQL 5.5
Mod_security 2.6.3

pillarsdotnet’s picture

Title: PHP Fatal error: Call to undefined function user_access() in rules/rules.module on line 916 » PHP Fatal error: Call to undefined function user_access() in rules/rules.module on line 916

restoring issue title

fago’s picture

Status: Active » Closed (fixed)

Please, always try the latest dev version and make sure the bug still exists there. If so, re-open.

presleyd’s picture

Status: Closed (fixed) » Active

I'm seeing this error (except on line 1194) with the current dev version.

fonant’s picture

I'm getting this too, line 1194. Started when I disabled a load of modules (using Admin Menu's "disable developer modules") and then found I had to re-enable many for Drupal Commerce to work.

A visit to http://sitename/admin/modules seems to have cleared the problem.

Fred75’s picture

Hello,

I have the same problem, among others, with both the regular (7.x-2.1) and dev (7.x-2.x-dev) versions of Rules + release 7.12 of core.
See here for a more detailed account: http://drupal.org/node/1068168#comment-5870496

Cheers,

Fred

mbelos’s picture

I ran into this on a production site. I set the "Show debug information" setting to "Never" on this page: /admin/config/workflow/rules/settings

Since the site is on production, I didn't need to show debug information anyway... Hope this helps some of you!

Anonymous’s picture

Priority: Normal » Major

I got it, too. In current dev it's line 1190: rules_show_debug_output(). It's very common - see this Google query - so I raise priority.

How about using function_exists('user_access') and completely disable debug output in case no access checks are possible? Just to get rid of it quickly...

Anonymous’s picture

Version: 7.x-2.0 » 7.x-2.x-dev
Component: Rules Engine » Rules Core
Anonymous’s picture

Status: Active » Needs review
StatusFileSize
new490 bytes
boabjohn’s picture

Also getting this problem. What can I provide to assist in debug? We're running:
1. Latest Rules7.x-2.x dev
2. A permissions module called field_permissions
3. Variable
...nothing else too tricky.
The patch in #21 looks stalled?
Do the maintainers feel this issue was resolved back in #8?

mitchell’s picture

@boabjohn: Did you test the patch?

@Shnapoo: It's probably best you create a new issue and backreference this one so that each commit is atomic. I'll leave this issue open in the meantime for any incoming test reports.

Anonymous’s picture

The commit #6 was refactoring, not solving the issue at all. At #0 the OP has already shown the solution. At #21 I simply reinvented it, because it wasn't handled properly for over a year.

So, I will not open a new issue. This one is not solved as yet, has no relevant commit.

mitchell’s picture

Title: PHP Fatal error: Call to undefined function user_access() in rules/rules.module on line 916 » Rules Debugger calls user_access() too early

@Shnapoo: Thank you for clarifying. I didn't see that #6 was only a refactoring. #21 looks to be what's needed.

I'd be happy to test if I knew how to reproduce this, but that's where we're at now. Tests wanted.

Aleksander Mlinšek’s picture

rules_exit.patch queued for re-testing.

andypost’s picture

Version: 7.x-2.x-dev » 7.x-2.2

Confirm that bug exists in 2.2

Krakott’s picture

To mbelos
(#18 Posted by mbelos on May 1, 2012 at 6:24am)

Thanks a lot, it worked for me !
This error only appeared in IE, not in Firefox

gunwald’s picture

I have the same problem:

PHP Fatal error:  Call to undefined function user_access() in /var/webs/drupal/sites/all/modules/rules/rules.module on line 1194

I am using Rules 7.x-2.3. The version is newer than the patch, what am I supposed to do than?

The strange thing is, that I am running that site for a long time and the error occurs (as far as I see) as from today. It seems to break the cron.

fago’s picture

Version: 7.x-2.2 » 7.x-2.x-dev
StatusFileSize
new532 bytes

Looks like the problem is rules_exit() not taking into account that it runs for cached page requests. Please test whether the attached patch does the trick.

denix’s picture

I agree, same problem. I start getting the error when using cache for anonymous.

Denis

fago’s picture

Status: Needs review » Fixed

although no testers reported whether #30 does the job, I think it does, so I went ahead and committed it.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

WebSinPat’s picture

the patch in #30 seems to have made my error go away.
rules 7.x-2.3