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

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

问题描述

我有 index.php 我希望在其中加入 class.twitter.php ,我该怎么办这样做?

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

希望当我把下面的代码放在index.php中时它会起作用。

Hopefully then 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天全站免登陆