twitteroauth icon indicating copy to clipboard operation
twitteroauth copied to clipboard

Fatal error: Class 'Abraham\TwitterOAuth\Config' not found in …

Open petebarr opened this issue 9 years ago • 25 comments

Hi,

I've been going through loads of previous issues here to try and see if they could help with trying to get this to work for me, but I'm stumped. Sorry, I'm not a php dev, so I'm using the manual method as described :-(

require "twitteroauth/autoload.php"; use Abraham\TwitterOAuth\TwitterOAuth;

The full error is:

Fatal error: Class 'Abraham\TwitterOAuth\Config' not found in /var/www/vhosts/stagingtesting.com/subdomains/redtree.stagingtesting.com/wp-content/themes/redtree/includes/twitter/twitteroauth/src/TwitterOAuth.php on line 17

So I'm guessing I'm having paths issues.

It's a Wordpress site, so in footer.php I've got this:

<?php get_template_part('includes/twitter/get-tweets'); ?>

And it's in this get-tweets.php file that I'm requiring Twitteroauth as above. My twitteroauth directory is at the same level as this php file and the files are extracted as you described. I did a print_r on $base_dir in autoload.php and it returns this which I presume is not correct:

/var/www/vhosts/stagingtesting.com/subdomains/redtree.stagingtesting.com/wp-content/themes/redtree/includes/twitter/twitteroauth/src//var/www/vhosts/stagingtesting.com/subdomains/redtree.stagingtesting.com/wp-content/themes/redtree/includes/twitter/twitteroauth/src/

The path is double stacked.

One other thing to note is that it works on my local MAMP using php 7.1.0 but not on the live site with Shared hosting PHP 7.1 CGI (7.1.6).

Any thoughts on what's happening here? Sorry, I know you've been queried about this issue many times.

Thanks!

petebarr avatar Jul 25 '17 10:07 petebarr

What is the value of __DIR__ and $relative_class in autoload.php?

abraham avatar Jul 25 '17 11:07 abraham

I'm getting them both printing out twice as:

DIR = /var/www/vhosts/stagingtesting.com/subdomains/redtree.stagingtesting.com/wp-content/themes/redtree/includes/twitter/twitteroauth

REALTIVE CLASS = TwitterOAuth

DIR = /var/www/vhosts/stagingtesting.com/subdomains/redtree.stagingtesting.com/wp-content/themes/redtree/includes/twitter/twitteroauth

REALTIVE CLASS = Config

petebarr avatar Jul 25 '17 13:07 petebarr

$base_dir = __DIR__ . '/src/'; so I'm not sure how that would get the path twice as you originally mentioned.

abraham avatar Jul 25 '17 15:07 abraham

Yeah, there's nothing in a loop etc.

petebarr avatar Jul 25 '17 15:07 petebarr

I assume it shouldn't print out 2 relative classes either?

petebarr avatar Jul 25 '17 15:07 petebarr

I think having things print twice isn't a problem. It's not ideal to have the same code run twice but requiring a file multiple times won't break things. If the value printed once is a single string with the path twice than that is an issue.

abraham avatar Jul 25 '17 16:07 abraham

I don't suppose you would have any idea what might cause that if this is the issue?

petebarr avatar Jul 25 '17 16:07 petebarr

Try adding use Abraham\TwitterOAuth\Config as Config; after namespace Abraham\TwitterOAuth; in src/TwitterOAuth.php

abraham avatar Jul 25 '17 19:07 abraham

Unfortunately that gives the error:

Fatal error: Class 'Abraham\TwitterOAuth\Config' not found in /var/www/vhosts/stagingtesting.com/subdomains/redtree.stagingtesting.com/wp-content/themes/redtree/includes/twitter/twitteroauth/src/TwitterOAuth.php on line 18

petebarr avatar Jul 26 '17 08:07 petebarr

What version of PHP are you running?

abraham avatar Aug 10 '17 13:08 abraham

I have the same issue. Let us know if there is a solution to this problem.

pjethaliya avatar Aug 11 '17 15:08 pjethaliya

I made the new object as \Abraham\TwitterOAuth\TwitterOAuth. Before I use to make it like $connection = new TwitterOAuth and now changed it to $connection = new \Abraham\TwitterOAuth\TwitterOAuth.

This solved my problem. It was because of the namespaces thing.

pjethaliya avatar Aug 11 '17 16:08 pjethaliya

If you have use Abraham\TwitterOAuth\TwitterOAuth; this shouldn't be an issue. You might have a different issue from @petebarr.

What version of PHP are you using?

abraham avatar Aug 11 '17 18:08 abraham

7.1.8

petebarr avatar Sep 04 '17 13:09 petebarr


MazettePatacaisse avatar Sep 09 '17 07:09 MazettePatacaisse

Sorry abraham, my fault. I didn't realise that a prev developer had a gitignore on the Config file so it was missing. I hate my life! lol. Cheers for your help anyway, much appreciated!

petebarr avatar Sep 27 '17 09:09 petebarr

Similar issue here. I had a rule in Transmit to skip files named "config.php". Apparently it isn't case-sensitive. All sorted now.

WillJW avatar Oct 16 '17 10:10 WillJW

same here

jrmgx avatar Dec 12 '17 06:12 jrmgx

image image image image

Whats the issue for this error?

RobinPeter1090 avatar Dec 15 '17 09:12 RobinPeter1090

You're not following the installation instructions on https://twitteroauth.com/.

You should either use composer to install and load TwitterOAuth like this:

require "vendor/autoload.php";
use Abraham\TwitterOAuth\TwitterOAuth;

or download the files manually and load TwitterOAuth like this:

require "twitteroauth/autoload.php";
use Abraham\TwitterOAuth\TwitterOAuth;

abraham avatar Dec 18 '17 00:12 abraham