如何在PHP中包含一个类 [英] How to include a class in PHP

查看:89
本文介绍了如何在PHP中包含一个类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有文件index.php,并且我想在其中包含文件class.twitter.php.我该怎么办?

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

希望,当我将以下代码放入index.php时,它将起作用.

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();

推荐答案

您的代码应类似于

require_once('class.twitter.php');

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

$data = $t->publicTimeline();

这篇关于如何在PHP中包含一个类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆