Seems like I get the honor of posting the first bug report on this shiny new project page ;)
The error I get is:
Fatal error: Call to undefined function arg() in /opt/lampp/htdocs/modules/og_user_roles/og_user_roles.module on line 647
I think it might have referred to line 580 earlier, but that was in the previous version I believe. Also, I'm just about to update to the latest version from this project page, so the linenumber might not be accurate.
Anyway, as the error says, it seems like the problem is caused because of the Drupal core function arg() not having been loaded when og_user_roles calls it.
It happens on some occasions, usually when an user logs in and then presses the back-button of the browser after having just logged in, and he will be stuck on that error unless he types some other URL. It also happened pre-login for example when I tried to login with my mobile phone xhtml browser.
I have searched a bit for the answer, and seems this happens on some other modules too, and it only occurs while page caching is on. The problem disappears when I turn page caching off (in "admin/settings/performance"), which is ok for now, but the site I'm building should be able to handle lots of visitors at the same time, so caching is important.. and I expect other people will run into the same problem.
As the error says, the actual reason is that arg()-function hasnt been defined yet. Here are some issues/solutions that have been suggested / made on other modules that had the same error:
http://drupal.org/node/138633
http://drupal.org/node/106907
http://drupal.org/node/138633
http://drupal.org/node/62942
The usual suggestion is to just disable cache.. I guess that's the easiest way out. But if that's not an option, another suggestion (on http://drupal.org/node/82489#comment-189522) is to check if arg() is defined, like this:
if (function_exists('arg') && arg(0) == 'node' && (is_numeric(arg(1)) || is_numeric(arg(2)))) {
And thus only running the code if arg() exists. But I guess that would cause more problems, and arg() should always be defined, and it is used a lot. I hope the cache issue can be circumvented somehow, like creating a custom arg()-function, maybe by copying the code from http://api.drupal.org/api/4.7/function/arg :
function arg($index) {
static $arguments, $q;
if (empty($arguments) || $q != $_GET['q']) {
$arguments = explode('/', $_GET['q']);
$q = $_GET['q'];
}
if (isset($arguments[$index])) {
return $arguments[$index];
}
}
Of course, it should maybe not be named arg(), it probably gets re-declared later, but I guess creating and using a custom_arg(), could work. Seems like og_user_roles.module uses arg() 72-times, so I guess that would need a lot of work.
I'm also using shitloads of other modules, like the "Persistent Login"-module, which provides a "Remember me"-box.. and the error might only happen if the users hasnt yet chosen "remember me". Not sure about that yet. Maybe it's a drupal core problem after all.
In any case, the error is always referring to og_user_roles/og_user_roles.module ... so maybe it's doing something at some point that other modules usually don't do (before all others)?
Someone seemed to have digged deeper into this (for drupal 4.7) here:
http://drupal.org/node/62942#comment-102156 but maybe it's not the same thing.
Solving this might require a lot of work, and maybe isn't a top priority.. but then again, maybe it is solveable and someone already knows the solution :)?
| Comment | File | Size | Author |
|---|---|---|---|
| #8 | og_user_roles.module.070606d.patch | 2.91 KB | somebodysysop |
| #7 | og_user_roles.module.070606b.patch | 1.32 KB | somebodysysop |
| #5 | og_user_roles.module.070606.patch | 570 bytes | somebodysysop |
| #2 | og_user_roles.module.070605.patch | 524 bytes | somebodysysop |
Comments
Comment #1
bibo commentedMore info:
After updating to the latest version, the error with correct linenumber is:
Also, it seems that disabling my "Persistant login" module, didn't affect the error, I still get this error when I logout (at least on non-admin users, not sure if I get a different results as admin).
This might have something to do with the url having no arguments at all, and being in the domain root, like www.mydomain.com. Moving to the root gives me the error (after logout), and I only get rid of it by typing a working url, like www.mydomain.com/user/[myusername], so it is quite annoying.
Comment #2
somebodysysop commentedThanks for providing the correct line number.
Seems like an easy enough fix. First, I'm going to try the bootstrap solution. Please apply the attached patch and see if that does the trick.
Comment #3
bibo commentedThanks for the fast answer and patch. I did the patch, and it fixed the Fatal Error, so my page shows up, which is important :)
However, it generates this error:
I also get this during failed login.
So, I guess it's the same thing as here:
http://drupal.org/node/62942
I think this error only occured during logout, and I suppose at that time og_user_roles isnt really needed, as anonymous people don't have (group) user roles ... so would it work if user_roles wasnt loaded if arg()-is not specified? Or would this result into them gaining access to all group content?
Would wrapping it so that bootstrap only gets called if arg() isn't declared?
Anyway, this is a lot better than the page not showing because of a fatal error. I can of course turn off error notices for a live site, but maybe there's another way.
Comment #4
bibo commentedOps, I ment
I'm not seeing any header errors at the moment - so this seems fixed for now, yay :) Need some more testing tho.
Comment #5
somebodysysop commentedOK, try this patch.
Comment #6
bibo commentedThank you again. I did the patch, and I'm not getting the fatal error, but I still occasionally get these:
It seems It comes always when I do this: login -> logout -> go to site root (by clicking the logo) -> click again on logo (reload root page!)... and there it is, every other time. This means I get the error every other time I go to the page root (Ö_Ö). Definetily weird cache stuff.
Also, seems it always happens just after I've logged out.
Maybe one aproach would be to check if the user is logged in, before executing anything inside the function og_user_roles_init () ... and if no user is logged in, not load the function and thus skip the module (which I guess isn't used if there is no logged user with a role)?
Thanks alot for your help :)
Comment #7
somebodysysop commentedOK, try this patch. It only calls the bootstrap if arg() is not found AND the user is logged in.
Comment #8
somebodysysop commentedWhoops. Logic problem with last patch. As you said, the init code should only execute if the user is logged in. This resolves that issue.
Comment #9
bibo commentedI tried the patch, and tested a few pages while not logged in. On the second or third page I got the undeclared arg()-error again:
ld
Again, I would not get rid of the error with that user until I typed some working url (page root again wouldn't work. I got a normal pageview when I loaded www.mypage.com/user). Also that page turned to the same error after I tested another url and tried to go back to www.mypage.com/user.
So, unfortunately the patch didn't fix it just yet. Seems atm that the only way to get it to work for now, is to put the logincheck into an extra if-clause and wrap the rest of the function in it, so the function (and thus the whole module) doesn't do anything if no user is logged.
What I did was use your patch on the original module file, and then altered the og_user_roles_init ()-function like this:
I'm not sure if this is a good idea (if the module does something with unauthorized visitors), but I just tested it, and I'm getting no errors on any page at the moment :) I'm not sure how to exactly make new patches, so I can't add this as a patch myself atm.
I hope someone else who is using pagecaching can reproduce this error so there's someone else who can also test it. It seems to work for me now, but I have to test more (after sleeping).
Comment #10
bibo commentedHah, nice! Seems we posted the exact same solution almost at the same time.
I did something wrong with pasting the code, or maybe it was some filter error with the links. If I'm reading the patch correctly, it is more or less the same as this:
Gonna test the patch right away :)
Comment #11
bibo commentedTested patch, everything seems to work fine! So, this issue with pagecaching seems to be fixed. I'll test some more tomorrow, to be sure.
Thanks again for the awesome support.
Comment #12
somebodysysop commentedLooks like this is fixed. Thanks!
Comment #13
drupalina commentedfor the less sofisticated people... how and where exactly do I implement this code? I don't know anything about patches. I mean which file should I write it in??? and also in the top or bottom?
Comment #14
somebodysysop commentedJust go to the project page http://drupal.org/project/og_user_roles and download the latest 5.x-1.1 release. All the modifications to date are included there.
You should read up on patches here: http://drupal.org/patch/apply
Comment #15
(not verified) commented