PHP - Class 未找到,但需要
PHP - Class not found, but is required
我正在使用 Abraham TwitterOAuth PHP SDK。我将库包含在 index.php
的顶部(文件存在 + 我使用 <?php
)。
<?php
require 'inc/oauth/autoload.php';
var_dump(file_exists('inc/oauth/autoload.php')); //true
use Abraham\TwitterOAuth\TwitterOAuth;
下面,在 HTML 之间,我在 div
中包含一个 .php
文件,如下所示:
<?php include('div.php'); ?>
在这个 div.php
文件中,我实例化了 TwitterOAuth class,这会引发错误:
if (isset($_COOKIE['token']) && !empty($_COOKIE['token'])) {
$token = objectToArray(json_decode($_COOKIE['token']));
$connection = new TwitterOAuth(CONSUMER, SECRET, $token['oauth_token'], $token['oauth_token_secret']);
这会引发错误 Class 'TwitterOAuth' not found
。
备注
在我将代码移至 div.php
之前,它一直在运行。但是,我需要将它分开,因为将来我将使用 JQuery.
刷新 div
class 使用 Abraham\TwitterOAuth
命名空间 - 因此您必须包含它们或使用 fqn(完全限定的 class 名称)
$connection = new \Abraham\TwitterOAuth\TwitterOAuth(CONSUMER, SECRET, $token['oauth_token'], $token['oauth_token_secret']);
我正在使用 Abraham TwitterOAuth PHP SDK。我将库包含在 index.php
的顶部(文件存在 + 我使用 <?php
)。
<?php
require 'inc/oauth/autoload.php';
var_dump(file_exists('inc/oauth/autoload.php')); //true
use Abraham\TwitterOAuth\TwitterOAuth;
下面,在 HTML 之间,我在 div
中包含一个 .php
文件,如下所示:
<?php include('div.php'); ?>
在这个 div.php
文件中,我实例化了 TwitterOAuth class,这会引发错误:
if (isset($_COOKIE['token']) && !empty($_COOKIE['token'])) {
$token = objectToArray(json_decode($_COOKIE['token']));
$connection = new TwitterOAuth(CONSUMER, SECRET, $token['oauth_token'], $token['oauth_token_secret']);
这会引发错误 Class 'TwitterOAuth' not found
。
备注
在我将代码移至 div.php
之前,它一直在运行。但是,我需要将它分开,因为将来我将使用 JQuery.
class 使用 Abraham\TwitterOAuth
命名空间 - 因此您必须包含它们或使用 fqn(完全限定的 class 名称)
$connection = new \Abraham\TwitterOAuth\TwitterOAuth(CONSUMER, SECRET, $token['oauth_token'], $token['oauth_token_secret']);