CybotAS / CookiebotWP

This repository contains Addons that will make other plugins work with Cookiebot.
https://wordpress.org/plugins/cookiebot/
GNU General Public License v2.0
38 stars 24 forks source link

Cookiebot throws fatal error at activation #168

Closed dseegers closed 3 years ago

dseegers commented 4 years ago

When I try to activate the plugin it is throwing a fatal error:

Fatal error: Declaration of DI\Definition\Helper\ObjectDefinitionHelper::getDefinition($entryName) must be compatible with DI\Definition\Helper\DefinitionHelper::getDefinition(string $entryName): DI\Definition\Definition in /data/sites/web/xxxxx/subsites/xxxx/wp-content/plugins/cookiebot/addons/lib/ioc/php-di/php-di/src/DI/Definition/Helper/ObjectDefinitionHelper.php on line 21

image

phpgeek commented 4 years ago

Hi,

Thanks for reporting the issue.

We are investigate the error. Currently I have not been able to reproduce the error - are you able to help me with a few more details?

dseegers commented 4 years ago

I have this on my local machine and a development machine (Linux) Mac Osx on commit: 3911968d1bd535b96ad2bc2803672d488f9c36cb

image

dseegers commented 4 years ago

Well, I think I have found the problem.

When I look at the ObjectDefinitionHelper.php file (CookiebotWP-master/addons/lib/ioc/php-di/php-di/src/DI/Definition/Helper) it is looking for the interface DefinitionHelper.

When I look in this file, you see the next (this is the php-di in the plugin)

<?php
/**
 * PHP-DI
 *
 * @link      http://php-di.org/
 * @copyright Matthieu Napoli (http://mnapoli.fr/)
 * @license   http://www.opensource.org/licenses/mit-license.php MIT (see the LICENSE file)
 */

namespace DI\Definition\Helper;

/**
 * Helps defining container entries.
 *
 * @author Matthieu Napoli <matthieu@mnapoli.fr>
 */
interface DefinitionHelper
{
    /**
     * @param string $entryName Container entry name
     * @return \DI\Definition\Definition
     */
    public function getDefinition($entryName);
}

I also have a file in my vendor file, expecting Definition where it is breaking. How can I solve this and help to fix the problem :)?

<?php

declare(strict_types=1);

namespace DI\Definition\Helper;

use DI\Definition\Definition;

/**
 * Helps defining container entries.
 *
 * @author Matthieu Napoli <matthieu@mnapoli.fr>
 */
interface DefinitionHelper
{
    /**
     * @param string $entryName Container entry name
     */
    public function getDefinition(string $entryName) : Definition;
}
phpgeek commented 4 years ago

@dseegers

In your vendor folder. Did you install another PHP DI - that might be the reason why the plugin breaks.

You should be able to use the plugin out of the bug without installing any additional libraries through composer?

I will try to look more into it tomorrow morning.

/Johan

dseegers commented 4 years ago

@phpgeek.

The problem is that it is calling getDefinition($entryName). I have tested on two internal websites.

The first one has a plugin with php-di The other is an framework that has the same conflict https://github.com/offbeatwp

PHP-DI version in the plugin https://github.com/PHP-DI/PHP-DI/commit/a6c813bf6b0d0bdeade3ac5a920e2c2a5b1a6ce3

image

aytackokus commented 4 years ago

Hi @dseegers,

Which plugin did cause the issue with DI?

Take care,

Aytac

dseegers commented 4 years ago

Well I think that the problem is that the cookiebot uses an changed version of php-di. Without the definition, so it would conflict with other composer packages that use php-di

interface DefinitionHelper
{
    /**
     * @param string $entryName Container entry name
     */
    public function getDefinition(string $entryName) : Definition;
}
aytackokus commented 3 years ago

Fixed by https://github.com/CybotAS/CookiebotWP/pull/195