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?

Members fund testing for the Drupal project. Drupal Association Learn more


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

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


#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.

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(...))?


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
632 bytes
drupsup’s picture

@Leksat, fyi -


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


 php -i | grep -i 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] 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

juampynr’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

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.

zhouhana’s picture

I can't read PHP very well myself, so I just want to double check. Because of the recent security release to OAuth I'm trying to update the module for a few sites, and now I'd like to reapply the patches that were previously applied, so the sites don't lose any important functionality.

The release notes for OAuth say nothing about this patch being included in the non-dev branch. When I try to apply it through the command line I get this:

$ patch -p1 < oauth-fatal_error_class_OAuthException-1334528-11.patch
can't find file to patch at input line 8
Perhaps you used the wrong -p or --strip option?
The text leading up to this was:
|Index: sites/all/modules/oauth/lib/OAuth.php
|IDEA additional info:
|Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
|--- sites/all/modules/oauth/lib/OAuth.php	(date 1328724051000)
|+++ sites/all/modules/oauth/lib/OAuth.php	(revision )
File to patch: sites/all/modules/oauth/lib/OAuth.php

(By the way, why did I need to enter the path manually? It's the same path as specified in the patch.)

patching file sites/all/modules/oauth/lib/OAuth.php
Hunk #1 FAILED at 1.
1 out of 1 hunk FAILED -- saving rejects to file sites/all/modules/oauth/lib/OAuth.php.rej

What should I do now? I'm thinking that since the patch is so old maybe there's some kind of mismatch between it and the code that is now in 7.x-3.3 that would need to be reviewed?

ErikWegner’s picture

Just a guess here: do not use -p1, as -p means: ignore directory levels in the patch file, and the digit means one level. Effectively you loose the sites path. Either use -p0 or do not use it at all.

zhouhana’s picture

Thanks for the info about -p1 – I had no idea. I still get the same result without it, though.

fuzzy76’s picture

FWIW, here's a patch rolled against 6.x-2.02.