PHP包含不适用于TwitterOAuth.php,但是当我直接复制并粘贴其内容时,一切都很好 [英] PHP include doesn't work for TwitterOAuth.php, but when I copy and paste its contents directly everything is fine

查看:137
本文介绍了PHP包含不适用于TwitterOAuth.php,但是当我直接复制并粘贴其内容时,一切都很好的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在 https://github.com/abraham/twitteroauth <中包含TwitterOAuth.php时遇到问题/ a>使用Twitter API。

I am running into problems trying to include TwitterOAuth.php from https://github.com/abraham/twitteroauth to use the Twitter API.

我的问题是:我在TwitterOAuth.php和OAuth.php所在的目录中有一个名为twitter.php的文件文件。当我尝试使用此代码片段进行连接时:

My problem is this: I have a file called twitter.php in the same directory as my TwitterOAuth.php and OAuth.php files. When I try to use this snippet of code to connect:

include("TwitterOAuth.php");

//I actually fill in these values in my code, no worries...
$apikey = //"...";
$apisecret = //"...";
$accesstoken = //"...";
$accesssecret = //"...";

$connection = new TwitterOAuth($apikey, $apisecret, $accesstoken, $accesssecret);
print_r($connection);

我收到此错误(第239行是$ connection = new TwitterOAuth(...)行) :

I get this error (line 239 is the $connection=new TwitterOAuth(...) line):

致命错误:第239行/home/sites/(mydomain)/public_html/twitteroauth-master/src/twitter.php中未找到TwitterOAuth类

Fatal error: Class 'TwitterOAuth' not found in /home/sites/(mydomain)/public_html/twitteroauth-master/src/twitter.php on line 239

但是,如果我复制并粘贴TwitterOAuth.php文件的全部内容,则替换我调用的行include(TwitterOAuth.php);有了这些内容,一切正常。我也试过使用include_once,require和require_once,但没有用。

However, if I copy and paste the entire contents of the TwitterOAuth.php file, replacing the line at which I call include("TwitterOAuth.php"); with those contents, everything works fine. I've also tried using include_once, require, and require_once, to no avail.

请指教 - 我是PHP的新手,不知道为什么复制当include()没有时,粘贴工作。

Please advise - I am very new to PHP and have no idea why copying and pasting works when include() doesn't.

谢谢!

推荐答案

你应该修改:

include("TwitterOAuth.php");

进入:

include 'TwitterOAuth.php';
use Abraham\TwitterOAuth\TwitterOAuth;

能够访问 TwitterOAuth 它定义的命名空间。

to be able to access the TwitterOAuth in its defined namespace.

建议使用 include'< file>',因为 include 是一种特殊的语言结构,而不是函数,不应与函数混淆。

It is recommended to use include '<file>' because include is a special language construct, not a function, and should not be confused with a function.

这篇关于PHP包含不适用于TwitterOAuth.php,但是当我直接复制并粘贴其内容时,一切都很好的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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