mirakl / sdk-php-shop

Mirakl PHP SDK for sellers
30 stars 16 forks source link

E_COMPILE_ERROR on 1.15 #28

Closed marios88 closed 2 years ago

marios88 commented 2 years ago

Getting the following error on 1.15 on PHP 7.3, reverting to 1.14 works for now

"type" => "E_COMPILE_ERROR"
"message" => "Declaration of Mirakl\Core\Domain\Collection\MiraklCollection::offsetSet(Mirakl\Core\Domain\Collection\mixed $offset, $value): void must be compatible with ArrayAccess::offsetSet($offset, $value)"
jreinke commented 2 years ago

Hello,

When did you upgrade to v1.15.0 please? There was an error in the first tag version that I had to publish again. Can you try a composer update and tell me please?

Thank you.

marios88 commented 2 years ago

I really dont remember when i upgraded, tried your suggestion along with composer clearcache but still getting the same error

see excerpt from composer.lock

{
            "name": "mirakl/sdk-php-shop",
            "version": "1.15.0",
            "source": {
                "type": "git",
                "url": "https://github.com/mirakl/sdk-php-shop.git",
                "reference": "182387a2b0aa0750eef0260b37791791a7e921f2"
            },
            "dist": {
                "type": "zip",
                "url": "https://api.github.com/repos/mirakl/sdk-php-shop/zipball/182387a2b0aa0750eef0260b37791791a7e921f2",
                "reference": "182387a2b0aa0750eef0260b37791791a7e921f2",
                "shasum": ""
            },
            "require": {
                "ext-curl": "*",
                "guzzlehttp/guzzle": "~6.0 || ~7.0",
                "guzzlehttp/psr7": "~1.7 || ~2.0",
                "php": ">=7.2.0"
            },
            "require-dev": {
                "php-parallel-lint/php-parallel-lint": "^1.3",
                "phpunit/phpunit": "~9.0"
            },
            "type": "library",
            "autoload": {
                "files": [
                    "src/Mirakl/functions.php",
                    "src/Mirakl/autoload.php"
                ],
                "psr-4": {
                    "Mirakl\\": "src/Mirakl/"
                }
            },
            "notification-url": "https://packagist.org/downloads/",
            "license": [
                "proprietary"
            ],
            "authors": [
                {
                    "name": "Mirakl",
                    "email": "info@mirakl.com"
                }
            ],
            "description": "Mirakl provides a PHP SDK that wraps the Mirakl REST APIs in a lightweight library. This enables you to develop a fast, flexible and custom integration for your existing e-commerce solution.",
            "support": {
                "issues": "https://github.com/mirakl/sdk-php-shop/issues",
                "source": "https://github.com/mirakl/sdk-php-shop/tree/v1.15.0"
            },
            "time": "2022-05-03T06:51:17+00:00"
        },
jreinke commented 2 years ago

What is your project's directory structure please? Can you add a screenshot of the directories from the root to the Mirakl's SDK?

Thank you.

marios88 commented 2 years ago

Root is /home/*****/public_html/ Path to vendor "/home/*****/public_html/private/vendor/ Running from CLI "PWD" => "/home/*****/public_html"

here is the full error

^ array:4 [
  "type" => "E_COMPILE_ERROR"
  "message" => "Declaration of Mirakl\Core\Domain\Collection\MiraklCollection::offsetSet(Mirakl\Core\Domain\Collection\mixed $offset, $value): void must be compatible with ArrayAccess::offsetSet($offset, $value)"
  "file" => "/home/*****/public_html/private/vendor/mirakl/sdk-php-shop/src/Mirakl/Core/Domain/Collection/MiraklCollection.php"
  "line" => 9
]

If you need more info please let me know. Thank you very much for you time!

jreinke commented 2 years ago

Unfortunately it does not help. More precisely, can you give the path of the Composer autoload.php file please? And the path of the Mirakl's SDK root directory? I cannot reproduce the error with a classic project structure so maybe there is a specificity in yours.

Thank you.

marios88 commented 2 years ago

/home/*****/public_html/private/vendor/autoload.php /home/*****/public_html/private/vendor/mirakl/sdk-php-shop/src/Mirakl/autoload.php

jreinke commented 2 years ago

The paths look good. What action are you doing that generates the error E_COMPILE_ERROR?

jreinke commented 2 years ago

Can you also give the content of /home/*****/public_html/private/vendor/composer/autoload_psr4.php please?

marios88 commented 2 years ago

Sorry didn't have the time to look further into it, will get back to you as soon as possible

krehberg-apalis commented 2 years ago

Hello,

we have a similar problem.

I think it is because of type hinting "mixed" in several functions now.

But "mixed" is only available for type hinting in PHP 8.0 and above.

On PHP 7.3 it fails. Because "MiraklCollection::offsetSet(mixed $offset, $value)" is not compatible with PHP 7 version of ArrayAccess::offsetSet($offset, $value)

You already have a 7.x directory under "src". Should that be used to avoid the issues? How could we make use of that?

Best regards, Kai

jreinke commented 2 years ago

Hello @krehberg-apalis,

Yes the 7.x directory is a specific fallback for PHP 7.x versions but the call to this directory should be automatic thanks to the autoload.php file.

Can you try to execute the command composer dump-autoload and see if the bug persists please?

Thank you.

krehberg-apalis commented 2 years ago

Hello @jreinke,

i reinstalled version 1.15 - including "composer dump-autoload -o" - and the issue is back.

Fatal error: Declaration of Mirakl\Core\Domain\Collection\MiraklCollection::offsetSet(Mirakl\Core\Domain\Collection\mixed $offset, $value): void must be compatible with ArrayAccess::offsetSet($offset, $value) in /var/www/clients/client1/web2/web/vendor/mirakl/sdk-php-shop/src/Mirakl/Core/Domain/Collection/MiraklCollection.php on line 9

These are the entries in vendor/composer/autoload_psr4.php

'Mirakl\\' => array($vendorDir . '/mirakl/sdk-php-shop/src/Mirakl'),
'MiraklSeller\\Sales\\' => array($vendorDir . '/mirakl/magento2-seller-connector/Sales'),
'MiraklSeller\\Process\\' => array($vendorDir . '/mirakl/magento2-seller-connector/Process'),
'MiraklSeller\\Core\\' => array($vendorDir . '/mirakl/magento2-seller-connector/Core'),
'MiraklSeller\\Api\\' => array($vendorDir . '/mirakl/magento2-seller-connector/Api'),
screenshot-mirakl-installed-versions
jreinke commented 2 years ago

Can you share the PHP versions you are using for the CLI and for the web server please?

krehberg-apalis commented 2 years ago

PHP 7.3.32 (cli) (built: Oct 28 2021 12:57:37) ( NTS ) Copyright (c) 1997-2018 The PHP Group Zend Engine v3.3.32, Copyright (c) 1998-2018 Zend Technologies with the ionCube PHP Loader + ionCube24 v11.0.0, Copyright (c) 2002-2021, by ionCube Ltd. with Zend OPcache v7.3.32, Copyright (c) 1999-2018, by Zend Technologies

Webserver Zend Engine v3.3.32, Copyright (c) 1998-2018 Zend Technologies with the ionCube PHP Loader + ionCube24 v11.0.0, Copyright (c) 2002-2021, by ionCube Ltd. with Zend OPcache v7.3.32, Copyright (c) 1999-2018, by Zend Technologies

jreinke commented 2 years ago

Thank you.

Then, do you think you can debug this line please? https://github.com/mirakl/sdk-php-shop/blob/master/src/Mirakl/autoload.php#L24

I would like to know if your vendor/autoload.php file can be found in one of the 2 possible paths of the $autoloadPaths variable.

krehberg-apalis commented 2 years ago

If i just use "composer dump-autoload" it works fine.

But if i use optimization, like "composer dump-autoload -o" or "composer dump-autoload -o --apcu", it doesnt work.

This file is used in the foreach loop: "/var/www/clients/client1/web2/web/vendor/mirakl/sdk-php-shop/src/Mirakl/../../../../../vendor/autoload.php"

jreinke commented 2 years ago

Thanks for the feedback.

I was able to reproduce the error, I will try to find a workaround when using the -o option.

jreinke commented 2 years ago

Hello,

The v1.15.1 has just been released and fixes the -o option usage.

Thanks again for your feedback.