robot-loader icon indicating copy to clipboard operation
robot-loader copied to clipboard

RobotAutoloader not load a interface

Open Pok4 opened this issue 1 year ago • 8 comments

Version: Last

I see this error - https://github.com/stripe/stripe-php/issues/1601 in my stripe api. I write there and i write here :) The error is because autoloader not load a exception interface. I open the cache and i see only one interface:

    'Stripe\\Exception\\OAuth\\ExceptionInterface' => 
    array (
      0 => 'C:\\xampp2\\htdocs\\ext\\pok4\\shop\\stripe\\lib\\Exception\\OAuth\\ExceptionInterface.php',
      1 => 1696003164,
    ),

in the bottom of the cache i see this: 'C:\\xampp2\\htdocs\\ext\\pok4\\shop\\stripe\\lib\\Exception\\ExceptionInterface.php' => 1696003164, maybe this is the problem - this is not load in the above clasess...

The content of this file is

<?php

namespace Stripe\Exception;

// TODO: remove this check once we drop support for PHP 5
if (\interface_exists(\Throwable::class, false)) {
    /**
     * The base interface for all Stripe exceptions.
     */
    interface ExceptionInterface extends \Throwable
    {
    }
} else {
    /**
     * The base interface for all Stripe exceptions.
     */
    // phpcs:disable PSR1.Classes.ClassDeclaration.MultipleClasses
    interface ExceptionInterface
    {
    }
    // phpcs:enable
}

Do you have any ideas how to load this in robotautoloader ?

Pok4 avatar Nov 06 '23 08:11 Pok4

This is by design, RobotLoader only loads classes that are always defined and not just in a condition.

dg avatar Nov 06 '23 10:11 dg

Yes, i get it, but there is a workaround to load it ? Maybe with custom variable ?

Pok4 avatar Nov 06 '23 10:11 Pok4

When i change the content of the file to:

<?php

namespace Stripe\Exception;


 
interface ExceptionInterface
{
}



everything is fine and worked correctly... I'm on PHP 8.1. Maybe the other part with if is not needed... The autoloader is loaded the file OK.

Pok4 avatar Nov 06 '23 10:11 Pok4

I tried adding $topLevelOnly 3ccc6fd3143827bf1cd0bc739854a7d8da88e43f. Try dev-master pls.

dg avatar Nov 06 '23 12:11 dg

No, not working.. I update with dev master and delete the cache, but in the new cache doesnt find the class.. Only in the bottom: 'C:\\xampp2\\htdocs\\ext\\pok4\\shop\\stripe\\lib\\Exception\\ExceptionInterface.php' => 1699278834,

Now i try to add $loader->topLevelOnly = true; but without success...

Pok4 avatar Nov 06 '23 13:11 Pok4

Did you delete cache?

dg avatar Nov 06 '23 14:11 dg

Yes - 3 times.

Pok4 avatar Nov 06 '23 14:11 Pok4

Then I don't know what the problem is...

dg avatar Nov 06 '23 16:11 dg