How to include a class in PHP

CLiown picture CLiown · Jan 3, 2010 · Viewed 129.4k times · Source

I have file index.php, and I want to include file class.twitter.php inside it. How can I do this?

Hopefully, when I put the below code in index.php it will work.

$t = new twitter();
$t->username = 'user';
$t->password = 'password';

$data = $t->publicTimeline();

Answer

Mez picture Mez · Jan 3, 2010

Your code should be something like

require_once('class.twitter.php');

$t = new twitter;
$t->username = 'user';
$t->password = 'password';

$data = $t->publicTimeline();