Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Including a class #36

Open
ghost opened this issue Feb 16, 2014 · 10 comments
Open

Including a class #36

ghost opened this issue Feb 16, 2014 · 10 comments

Comments

@ghost
Copy link

ghost commented Feb 16, 2014

Hey, I'm trying to add twitter functionality, but I'm having real trouble with autoloader.php trying to load my class or something?

PHP Fatal error: Uncaught exception 'Exception' with message 'File: "/home/steve/Desktop/bot/Classes/TwitterAPIExchange.php" not found.' in /home/steve/Desktop/bot/Classes/Autoloader.php:40

How can I do this?

@ElvenSpellmaker
Copy link
Collaborator

Classes need the correct namespace at the top of the file, otherwise the auto-loader will be looking in the wrong place.

Where is this current class defined and what namespace have you given it?

As an example If it's a command the namespace should be "Command" and the file should be contained inside the Classes/Command/ directory.

@ghost
Copy link
Author

ghost commented Feb 16, 2014

Hey,

I'm basically trying to implement https://github.com/J7mbo/twitter-api-php into the project in the form of a !twitter command. I'm just unsure how to include the required php (TwitterAPIExchange.php) file for it.

@ElvenSpellmaker
Copy link
Collaborator

OK, where have you put the file in the directory structure?

@ghost
Copy link
Author

ghost commented Feb 16, 2014

Everywhere. I either get a duplicate class error or an autoloader error. Where should I put it?

@ElvenSpellmaker
Copy link
Collaborator

I think you might be misunderstanding me. Where have you put the file "TwitterAPIExhange.php"?

If you put it in the same folder as the Autoloader.php and then when you want to use it call "new \TwitterAPIExchange($settings);".

The auto-loader will then kick in on the first load and load the file once.

@ElvenSpellmaker
Copy link
Collaborator

The point of an auto-loader is to never have to use require/require_once/include or include_once yourself which tidies up the code and also avoids the multiply defined classes problems.

@ghost
Copy link
Author

ghost commented Feb 16, 2014

Oh, excellent. Thanks!

@ElvenSpellmaker
Copy link
Collaborator

No problem. =)

I assume your issue is now resolved?

@ghost ghost closed this as completed Feb 16, 2014
@ghost ghost reopened this Sep 23, 2014
@ghost
Copy link
Author

ghost commented Sep 23, 2014

Hey, I'd like to use 'simple_html_dom.php' and it's not a class. I'm not having much luck guessing where to put him. Could you spoon-feed me? :)

@NanoSector
Copy link
Contributor

Do you want to use that for a command?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants