XF 2.2 ErrorException: Fatal Error: Cannot declare class

Dannymh

Active member
Hi All,

I write a plugin that has grown somewhat and is now getting more complex for my site and a few other sites.

One of the parts of the plugin modify the API POST class to action the deletion of content. It also modifies a few other classes.

It was all working fine however now I am getting the following error

Code:
[LIST]
[*]ErrorException: Fatal Error: Cannot declare class Silvertails\CrossForumChat\XF\Api\Controller\Post because the name is already in us             
[*]src/addons/Silvertails/CrossForumChat/XF/Api/Controller/Post.php:11          
[/LIST]

I am not modifying that class under the same namespace and there is no duplicate in the class extensions. I assume using the same

Code:
class Post extends XFCP_Post
{

Under different namespaces should work fine but I cant see any other reason this would occur.

Here is a list of class extensions
1684235683083.webp

are the
Silvertais\CrossForumChat\XF\API\Controller\Post and Silvertails\CrossForumChat\XF\Pub\Controller\Post possibly interfering with each other?

Really stuck on whats causing this conflict but can only assume those two are for some reason not seeing themselves under different namespaces
 
Never mind, I am a moron. I was using the same class name in the extension.

If there are any other tired people out there who come across something like this, note,
1- Go to bed and sort it in the morning
2 - Your class name and XFCP_xxx can be whatever you like it to be
 
There should be no issue with having multiple class extensions with the same name, there's classes named the same throughout XF. It sounds like you don't have a namespace in your extended file. You'll need to add something like namespace Silvertails\CrossForumChat\XF\Api\Controller; to the top of the file, the same way the XF classes are namespaced.
 
There should be no issue with having multiple class extensions with the same name, there's classes named the same throughout XF. It sounds like you don't have a namespace in your extended file. You'll need to add something like namespace Silvertails\CrossForumChat\XF\Api\Controller; to the top of the file, the same way the XF classes are namespaced.
No all files are namespaced, it was the duplicate class.

I just renamed the file and the class to postb and changed the class extension and everything worked fine
 
That's the point though, you can't get duplicated class names when using namespaces unless it's the same class name in the same namespace, which it wouldn't be here (otherwise it wouldn't work in core XF either). You must be doing something else strange if the classes are namespaced and you're still getting a duplicate class name in the same namespace, either that or trying to extend the same exact class twice which isn't necessary. You shouldn't need to be renaming any files or classes at all.
 
That's the point though, you can't get duplicated class names when using namespaces unless it's the same class name in the same namespace, which it wouldn't be here (otherwise it wouldn't work in core XF either). You must be doing something else strange if the classes are namespaced and you're still getting a duplicate class name in the same namespace, either that or trying to extend the same exact class twice which isn't necessary. You shouldn't need to be renaming any files or classes at all.
Don't know what to tell you the first line of ever file is

"namespace Silvertails\CrossForumChat\XF\Api\Controller;"
or
"namespace Silvertails\CrossForumChat\XF\Pub\Controller;"

where appropriate

They duplicate where they exist under the same namespace but the class names don't duplicate under the same namespace.
in other words I have two under the name space of
"namespace Silvertails\CrossForumChat\XF\Api\Controller;"
but that is "post" and the second "Posts" but they arent duplicates.

It is what it is, I have a working solution though as strange as the issue is.
 
Back
Top Bottom