duanba4254 2018-11-08 10:12
浏览 101
已采纳

如何调试PHP composer autoloader

Im trying to use the HiPay php library. I installed the library with:

composer require hipay/hipay-fullservice-sdk-php

Resulting in a vendor directory with the HiPay library in it. In my order.php page I use

<?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']);

but I get i Class Not Found error on

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

It works on my local win 10 computer running XAMPP but it dont work when I upload the code to my hosting. I have check for missmatches in filnames but I cant spot the whats wrong.

This is the error:

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

and the vendor dir created by composer

vendor dir from filezilla

but how can I figure out what is wrong? And debug autoload.php? Sorry for newbie questions. Im a newbie at PHP

Update 1:

I did a "print_r" of the aulotloader

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

and got this result from the hosting site were it doesnt work

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; 
)

the only difference between the not working and working local XAMPP sites print_r output is

[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
                )

        )

so I renamed the HiPay folder to hipay and everythings works. Lesson learned, use "print_r" to debug your autoloder fckps

  • 写回答

1条回答 默认 最新

  • dongtang5057 2018-11-08 15:15
    关注

    The code you have uploaded on server will be running on Linux which is case sensitive but in Windows operating system this doesn't matter.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 乘性高斯噪声在深度学习网络中的应用
  • ¥15 运筹学排序问题中的在线排序
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥30 python代码,帮调试,帮帮忙吧