Fatal error: Cannot redeclare class OAuthException in sites/all/modules/oauth/oauth.lib.php on line 17

I am getting this WSOD error right after login in. If I refresh the page, it goes away. I have looked high and low for any possible conflict with OAuth within all my contrib modules and cannot find one BUT I have an installation of STATUS.NET in a subdirectory. Could this be the problem?

Comments

karlitos’s picture

Same here,

getting this error in the logs, after every cron.

psykomf’s picture

I have the same problem with my drupal 6 site. can't run cron and it gives this error. Any advice would be appreciated

ravi.kumar’s picture

Hi,
Have you found any solution for this, I am facing the same error

Error: Cannot redeclare class OAuthException in /sites/all/modules/oauth/oauth.lib.php, line 17
WD cron: Cron run exceeded the time limit and was aborted.

Fatal error: Cannot redeclare class OAuthException in /sites/all/modules/oauth/oauth.lib.php on line 17
Drush command terminated abnormally due to an unrecoverable error.

ErikWegner’s picture

I had this issue, too. It was because I updated from 2.02 to 3.0b4 without removing the module directory, instead I just put all files into the existing directory. After deleting the oauth directory and placing a fresh version, the error is gone (see also #958126: Extra class OAuthException Declaration?)

karlitos’s picture

ErikWegner

#4 -> BINGO!!!!! I cleaned the system tables from oauth and I install it again and it works with no error whatsoever

ravi.kumar’s picture

Error fixed after upgrading OAuth module to latest version, as both OAuth and OAuth common modules are merged to single OAuth module.

buildyourbox’s picture

Thanks ErikWegner, post #4 worked for me.

Regards,
Build Your Box.
Any feedback appreciated.

kylebrowning’s picture

Status:Active» Closed (won't fix)
yuriy.babenko’s picture

I was getting the same error in 7.x-3.0 (and 7.x-3.0-dev). Single 'class OAuthException' instance in entire codebase, but 'cannot redeclare class' error being thrown. Turned out that my PHP installation was compiled with OAuth, so that's where the first copy of the class was coming from. Perhaps it's a good idea to move the OAuth.php file inclusion out of oauth_common.info and into the module, and wrap it in a if (!class_exists(...))?

//edit:

Wrapping just the OAuthException class declaration in a if (!class_exists(...)) did the trick for my system. In hindsight, using namespaces may be a possible solution here.

Leksat’s picture

Status:Closed (won't fix)» Active

If PHP installation has OAuth extension, loading of OAuth.php fails with fatal error because OAuth extension already contains OAuthException class.
IMO, the solution from #9 (wrapping with class_exists()) is the right way. Because sometime, for instance on shared hosting, we have no ability to manage PHP extensions.

Leksat’s picture

Priority:Normal» Major
Status:Active» Needs review
StatusFileSize
new632 bytes
drupsup’s picture

@Leksat, fyi -

with

Core                         System (system)                                  Module  Enabled        7.15          
OAuth                        OAuth (oauth_common)                             Module  Enabled        7.x-3.0+15-dev

and

php -i | grep -i oauth
  OAuth
  OAuth support => enabled
  source version => $Id: oauth.c 308063 2011-02-06 17:22:05Z jawed $

getting this error:

==> /var/log/apache2/drupsup.int.error_log <==
[Thu Aug 23 15:06:39.373665 2012] [proxy_fcgi:error] [pid 20730:tid 139942593435392] [client 127.0.0.1:50089] AH01071: Got error 'PHP message: PHP Fatal error:  Cannot redeclare class OAuthException in /home/drupsup/drupal7/sites/all/modules/contrib/oauth/lib/OAuth.php on line 8\n', referer: https://drupsup.int/user/login

applying patch @ #11; applies successfully to D7+OAuth7x3.

No more error.

drupsup’s picture

Version:6.x-3.x-dev» 7.x-3.x-dev
alandarev’s picture

I installed pecl OAuth for php in order to communicate with OAuth services, and Drupal site stopped working due to redeclaration of OAuthException.

Patch in comment #11 indeed works well and solved my problem. I am hoping to see it included in next version

ppfranco’s picture

applied patch and no more errors!! THAnKS!!! #11...D7

juampy’s picture

Status:Needs review» Fixed

Status:Fixed» Closed (fixed)

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

muhammad.tanweer’s picture

#4 works for me. Thanks for the clue. I removed the directory of oAuth and replaced with new version of the module. All worked.

Muhammad Tanweer
http://www.app-desk.com

sahirmathur’s picture

Issue summary:View changes

I tried this and it didnt work for me, replaced the oauth directory with a new latest copy from https://www.drupal.org/project/oauth

Does anyone know how to install the patch file? I am on a shared host

ErikWegner’s picture

You can either

a) download the file from the repository ( go to http://cgit.drupalcode.org/oauth/tree/lib/OAuth.php and select your module version, then use the whole file) or

b) download your current file from your shared host (sites/all/modules/oauth/lib/OAuth.php
), download the diff, apply the diff and upload the modified file to the shared host. Because the diff is small, you can even edit the OAuth.php by hand. Just look into the diff file, it is plain text.

Good luck.