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

查看:36
本文介绍了PHP include 不适用于 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 '' 因为 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 include 不适用于 TwitterOAuth.php,但是当我直接复制并粘贴其内容时,一切正常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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