• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

XFCP class being redeclared?

Liam W

Well-known member
#1
I am getting the error message:

Fatal error: Cannot redeclare class XFCP_UserReferrals_ControllerPublic_Register in C:\xampp\htdocs\xenforo\library\XenForo\Application.php(410) : eval()'d code on line 1
since I logged out.

I don't know what's causing this - the last time I got this, I had two files with the same class name for two different addons, but I don't this time.

Any ideas?
 

Chris D

XenForo developer
Staff member
#2
It definitely is this:
I had two files with the same class name
That's the standard error PHP throws when the same class name is redeclared.

You will need to disable add-ons and enable each one to work out which one is causing it.
 

Jake Bunce

XenForo moderator
Staff member
#5
I think it has something to do with that, although I'm not sure what 'that' is. How would I fix it? I'm extending a controller that is being called by a reroute.

(The register one)
You are only extending the register controller? Nothing else?
 

Jake Bunce

XenForo moderator
Staff member
#8
Can you post all relevant addon code? The listener and the actual extended class?

What action is triggering this error?

edit - ninjaaaaaa
 

Liam W

Well-known member
#9
Can you post all relevant addon code? The listener and the actual extended class?

What action is triggering this error?

It's just a redeclared php error.

Also, I belive this is what you want:

PHP:
public static function listener($class, array &$extend)
{
    if ($class = 'XenForo_ControllerPublic_Register')
    {
        $extend[] = 'UserReferrals_ControllerPublic_Register';
    }
}
PHP:
<?php
 
class UserReferrals_ControllerPublic_Register extends XFCP_UserReferrals_ControllerPublic_Register
{
 
    public function actionRegister()
    {
 
        parent::actionRegister();
 
        $session = $cookies = XenForo_Application::getSession();
 
        if($referringuser = $session->get('referral_id'))
        {
 
            $dw = XenForo_DataWriter::create('UserReferalls_DataWriter_DataWriter');
            $dw->set('userid', XenForo_Visitor::getUserId());
            $dw->set('referred_by', $referringuser);
            $dw->save();
        }
 
    }
 
    public function _getModel()
    {
        return $this->getModelFromCache('UserReferrals_Model_Model');
    }
 
}
 

Chris D

XenForo developer
Staff member
#10
This is wrong:

PHP:
public static function listener($class, array &$extend)
{
    if ($class = 'XenForo_ControllerPublic_Register')
    {
        $extend[] = 'UserReferrals_ControllerPublic_Register';
    }
}
Should be $class == 'XenForo_ControllerPublic_Register'
 

Jake Bunce

XenForo moderator
Staff member
#11
PHP:
public static function listener($class, array &$extend)
{
    if ($class = 'XenForo_ControllerPublic_Register')
    {
        $extend[] = 'UserReferrals_ControllerPublic_Register';
    }
}
if ($class = 'XenForo_ControllerPublic_Register') ......

You need a double equals for comparison.