Search code examples
phpcomposer-phpautoloader

How to debug 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


Solution

  • 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.