如何调试PHP Composer自动加载器

时间:2018-11-08 10:12:47

标签: php composer-php autoloader

我正在尝试使用HiPay php库。我用以下方法安装了库:

composer require hipay/hipay-fullservice-sdk-php

生成包含HiPay库的供应商目录。在我的order.php页面中,使用

<?php
namespace TokenizationExample;

require __DIR__ . '/config/credentials.php';
require __DIR__ . '/vendor/autoload.php';

$config = new \HiPay\Fullservice\HTTP\Configuration\Configuration($credentials['private']['username'], $credentials['private']['password']);

但是我收到“找不到类”错误

$config = new \HiPay\Fullservice\HTTP\Configuration\Configuration($credentials['private']['username'], $credentials['private']['password']);

它可以在运行XAMPP的本地win 10计算机上运行,​​但是当我将代码上传到托管服务器时它不起作用。我可以检查filname中的不匹配项,但无法发现问题所在。

这是错误:

Fatal error: Uncaught Error: Class 'HiPay\Fullservice\HTTP\Configuration\Configuration' not found in /home/XXXXX/order.php:8 Stack trace: #0 {main} thrown in /home/XXXXX/order.php on line 8

以及由作曲家创建的供应商目录

vendor dir from filezilla

但是我如何找出问题所在?和调试autoload.php?对不起,新手问题。我是PHP的新手

更新1:

我做了aulotloader的“ print_r”

$autoloader = require __DIR__ . '/vendor/autoload.php';
print_r($autoloader,true)

并从托管站点获得了此结果,如果它不起作用

Composer\Autoload\ClassLoader Object
(
    [prefixLengthsPsr4:Composer\Autoload\ClassLoader:private] =&gt; Array
        (
            [H] =&gt; Array
                (
                    [HiPay\Fullservice\] =&gt; 18
                )

        )

    [prefixDirsPsr4:Composer\Autoload\ClassLoader:private] =&gt; Array
        (
            [HiPay\Fullservice\] =&gt; Array
                (
                    [0] =&gt; /home/XXXXX/vendor/composer/../hipay/hipay-fullservice-sdk-php/lib/HiPay/Fullservice
                )

        )

    [fallbackDirsPsr4:Composer\Autoload\ClassLoader:private] =&gt; Array
        (
        )

    [prefixesPsr0:Composer\Autoload\ClassLoader:private] =&gt; Array
        (
        )

    [fallbackDirsPsr0:Composer\Autoload\ClassLoader:private] =&gt; Array
        (
        )

    [useIncludePath:Composer\Autoload\ClassLoader:private] =&gt; 
    [classMap:Composer\Autoload\ClassLoader:private] =&gt; Array
        (
        )

    [classMapAuthoritative:Composer\Autoload\ClassLoader:private] =&gt; 
    [missingClasses:Composer\Autoload\ClassLoader:private] =&gt; Array
        (
        )

    [apcuPrefix:Composer\Autoload\ClassLoader:private] =&gt; 
)

本地XAMPP网站print_r输出与不工作之间的唯一区别是

[prefixDirsPsr4:Composer\Autoload\ClassLoader:private] =&gt; Array
        (
            [HiPay\Fullservice\] =&gt; Array
                (
                    [0] =&gt; C:\xampp\htdocs\hipay-example\vendor\composer/../hipay/hipay-fullservice-sdk-php/lib/HiPay/Fullservice
                )

        )

所以我将HiPay文件夹重命名为hipay,一切正常。获得的经验教训,请使用“ print_r”调试您的自动翻译器f ck ps

1 个答案:

答案 0 :(得分:0)

您在服务器上上传的代码将在区分大小写的Linux上运行,但是在Windows操作系统中则无关紧要。