【发布时间】:2019-01-30 22:37:48
【问题描述】:
问题:
我有一个 index.php 文件,它有几个作曲家依赖项。
在index.php 文件中,我试图在不同的php(比如说auth.php)文件中从外部类调用静态方法,如下所示:
/*creating a class instance*/
$var = new AuthClass();
/*accessing an outside class method*/
$var = AuthClass::checkTime($tokenCode);
问题是类中的 checkTime 方法也需要一个 composer 依赖项,虽然该文件与 index.php 位于同一文件夹中并且包含 index.php,但该文件不被继承。
PHP Fatal error: Uncaught Error: Class 'Token' not found
我已经尝试了所有方法 - 从添加 require_once/include 'index.php' 到将 composer autoload 复制到 AuthClass 代码内外的 auth.php,但没有任何效果,我仍然遇到同样的错误。
附加代码:
index.php
require __DIR__ . '/src/vendor/autoload.php';
$argument1 = $_GET['argument1'];
$tokenCode = $_GET['tokenCode'];
include 'config/database.php';
include 'objects/program1.php';
include 'auth.php';
use ReallySimpleJWT\Token;
use Carbon\Carbon;
$secret = "somesecret";
if (($_SERVER['REQUEST_METHOD']) == "GET") {
if ($_GET['url'] == "bankquery") {
if($tokenCode===NULL){
echo "no correct token provided";
print($results);
} else {
$results = Token::validate($tokenCode, $secret);
if ($results = 1){
$var = new AuthClass();
$var = AuthClass::checkTime($tokenCode);
} else {
echo "no correct token provided";
}
}
} else {
echo "some GET other query";
}
?>
auth.php
// loading composer
require __DIR__ . '/src/vendor/autoload.php';
//loading my index.php file
include 'index.php';
//using composer dependencies
use ReallySimpleJWT\Token;
use Carbon\Carbon;
class AuthClass{
public static function checkTime($tokenCode){
// getting payload from token code by accessing the composer dependency method in a class Token
$received = Token::getPayload($tokenCode);
return $received;
}
}
?>
需要帮助,伙计们。
【问题讨论】:
-
没有足够的信息。请提供一些关于 Token 类的信息
-
@DavitHuroyan 提供了代码
-
在 Token " \Token" 之前尝试 \ 或尝试使用命名空间让我们看看会返回什么
-
那么
index.php的内容是什么? -
尝试了 "\Token" 和命名空间 "ReallySimpleJWT\Token" 都没有工作,同样的错误,不幸的是@DavitHuroyan
标签: php class dependencies composer-php