super3 / IRC-Bot

A very little basic IRCBot that will get improved over the next time.
http://www.wildphp.com
102 stars 47 forks source link

Including a class #36

Open ghost opened 10 years ago

ghost commented 10 years ago

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 commented 10 years ago

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 commented 10 years ago

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 commented 10 years ago

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

ghost commented 10 years ago

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

ElvenSpellmaker commented 10 years ago

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 commented 10 years ago

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 commented 10 years ago

Oh, excellent. Thanks!

ElvenSpellmaker commented 10 years ago

No problem. =)

I assume your issue is now resolved?

ghost commented 9 years ago

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 commented 9 years ago

Do you want to use that for a command?