XenForo_Model override issue (perhaps?)

Hello everyone,

I have been working on an extension for a client of mine and ran across a slight problem, which I managed to solve, but with a workaround.

Consider the following:
- XenForo_Model has a method called "prepareStateLimitFromConditions" I want to override.
- I have a MyExtension_Model_Post and a MyExtension_Model_Thread class, both registered in my listener to extend the originals. They originally already override a lot of methods, except for "prepareStateLimitFromConditions", which is yet to be implemented at this point.

Since both these class have to use the same "prepareStateLimitFromConditions"-method, I figured I'd just make a MyExtension_Model extending XFCP_MyExtension_Model with said method defined.

Since it's no use trying to add a listener for XenForo_Model, I figured I just add two extends to XenForo_Model_Post and XenForo_Model_Thread. The first one to MyExtension_Model, the second to either MyExtension_Model_Post or MyExtension_Model_Thread respectively.

However, this generates an error where it tells me you can't extend from the same class twice.

Eventually I "solved" it by removing changing MyExtension_Model back to just a class, making the method static, then override method in the two classes twice, just calling the static method.

I was wondering, where did I go wrong, because I don't like my "hack", and it seems my initial way of solving it should have worked.
 
A little bit more information...
PHP:
case 'XenForo_Model_Thread':
    $extend[] = 'MyExtension_Model'; //Contains the prepareStateLimitFromConditions override
    $extend[] = 'MyExtension_Model_Thread'; //Contains other overrides
    break;

case 'XenForo_Model_Post':
    $extend[] = 'MyExtension_Model'; //Contains the prepareStateLimitFromConditions override
    $extend[] = 'MyExtension_Model_Post'; //Contains other overrides
    break;

My class definitions:
PHP:
class MyExtension_Model extends XFCP_MyExtension_Model
class MyExtension_Model_Thread extends XFCP_MyExtension_Model_Thread
class MyExtension_Model_Post extends XFCP_MyExtension_Model_Post

Will throw an error
PHP:
Fatal error: Cannot redeclare class XFCP_MyExtension_Model in D:\Websites\Dev\library\XenForo\Application.php(520) : eval()'d code on line 1

How come? It works fine in most other cases.
 
Last edited:
You are loading MyExtension_Model twice in the listener. You should remove it from one of the case.
 
If I remove it from one of the cases, one of the two will not have the prepareStateLimitFromConditions overwritten, so that can't be the solution, right?
 
Back
Top Bottom