spatie / wordpress-ray

Debug with Ray to fix problems faster in WordPress apps
https://myray.app
MIT License
73 stars 14 forks source link

Cannot declare trait because name is already in use #36

Closed adamtomat closed 3 years ago

adamtomat commented 3 years ago

When installing the Ray WordPress plugin, we get the following errors when it has been activated.

Fatal error: Cannot declare trait Spatie\WordPressRay\Spatie\Macroable\Macroable, because the name is already in use in /path/site/web/app/plugins/wordpress-ray/vendor/spatie/macroable/src/Macroable.php on line 10

Fatal error: Cannot declare interface Spatie\WordPressRay\Psr\Container\ContainerExceptionInterface, because the name is already in use in /path/site/web/app/plugins/wordpress-ray/vendor/psr/container/src/ContainerExceptionInterface.php on line 11

I've tried to rule out as much as I can and I believe it is conflicting with our theme (as I've tested it works fine on a standard install of WP and the 2021 theme).

Our theme is built on a WordPress MVC framework called Lumberjack (https://docs.lumberjack.rareloop.com/). On a fresh install of this theme I can replicate the errors above.

Lumberjack uses thespatie/macroable package (added via composer) to allow for extension of the framework classes. It seems like this is causing a conflict with the macroable dependency within the plugin.


I setup a fresh install of Lumberjack (as per these install instructions). I removed everything the framework does until I got a blank white page. I slowly started adding in parts of Lumberjack and the first time it errors is with our Router:

<?php

use Spatie\Macroable\Macroable;

class Router implements Routable
{
    use VerbShortcutsTrait, Macroable;

When I remove the Macroable trait and namespace from this file, the error goes.


Now, I'll be honest. I don't actually know why PHP is giving this error considering the spatie macroable namespace we use is different than the one included in the plugin (namespace Spatie\WordPressRay\Spatie\Macroable\Macroable;). Any insights here would be fab.

I'm happy to provide the bare-bones theme if that is useful but my theory is that this issue occurs when a site already brings in a dependency (via composer) that the plugin uses too (e.g. macroable) - so while is occurs in our Lumberjack theme, it is not exclusive to it.

Note that we are able to use the standard PHP ray library via composer - it's just this plugin that causes the issue.

freekmurze commented 3 years ago

Will be fixed through #39