'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
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] => Array
(
[H] => Array
(
[HiPay\Fullservice\] => 18
)
)
[prefixDirsPsr4:Composer\Autoload\ClassLoader:private] => Array
(
[HiPay\Fullservice\] => Array
(
[0] => /home/XXXXX/vendor/composer/../hipay/hipay-fullservice-sdk-php/lib/HiPay/Fullservice
)
)
[fallbackDirsPsr4:Composer\Autoload\ClassLoader:private] => Array
(
)
[prefixesPsr0:Composer\Autoload\ClassLoader:private] => Array
(
)
[fallbackDirsPsr0:Composer\Autoload\ClassLoader:private] => Array
(
)
[useIncludePath:Composer\Autoload\ClassLoader:private] =>
[classMap:Composer\Autoload\ClassLoader:private] => Array
(
)
[classMapAuthoritative:Composer\Autoload\ClassLoader:private] =>
[missingClasses:Composer\Autoload\ClassLoader:private] => Array
(
)
[apcuPrefix:Composer\Autoload\ClassLoader:private] =>
)
the only difference between the not working and working local XAMPP sites print_r output is
[prefixDirsPsr4:Composer\Autoload\ClassLoader:private] => Array
(
[HiPay\Fullservice\] => Array
(
[0] => 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 1:[1]
ensure Installation of the package worked
composer show | grep thepackageiwant
if in doubt, reinstall without cache and loglevel debugcomposer --no-cache -vvv require thepackageiwantFor making sure to capture all potentially different locations where require(autoload.php) happens, proceed from vendor/autoload.php
Create Logs invendor/autoload.php, add them to a logfile - depending on your code a print_r or var_dump will interfere with other things
<?php
// autoload.php @generated by Composer
$timestamp = system('date +%s%N');
# to make sure you reach that far (you did require the autoload.php, right?!), add to first line in function getLoader, create/append to logfile
file_put_contents(__DIR__.'/_composer.log',print_r([$timestamp,'Autoloader Required by', debug_backtrace()],true),FILE_APPEND);
require_once __DIR__ . '/composer/autoload_real.php';
$loader = ComposerAutoloaderInit1fea3bd4e26e1ee7a171c20cea87d467::getLoader();
# The returned loader should include the classes and their path in case sensitive way corresponding to the actual path name in your file system
# If the classes aren't included, go back to Start, if they are, check if you can use the package path when pasting it in your terminal/system explorer
file_put_contents(__DIR__.'/_composer.log',print_r([$timestamp,'Composer Autoload returns', $loader],true),FILE_APPEND);
return $loader;
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | til |

