XF 2.0 Resource Standards & Overriding methods

Kirby

Well-known member
If a class extension is required to extend core methods then it must be extended properly, rather than overridden, by calling the parent method.
While I fully support this, I think that this rule can be problematic:
In some (really rare) cases it is "necessary" to completely override a parent method.

Example
I want to prevent misc/locationinfo from being usable. To do this, I'd normally just override \XF\Pub\Controller\Misc::actionLocationInfo() to return a nice error message like "This functionality has been administratively disabed".

As this would not be allowed according to a/m rule, I would have to do this in a more complicated & inefficient way, for example by hooking into preDispatch.

@Chris D
What would be the preferred solution/advise here?
 
That particular use case would be acceptable because you're actually not intending to extend - you are intending to override. You're also intending that your own code shouldn't be overridden, presumably, so I guess you'll also couple it with a super high execution order.

This guideline is mostly targeting developers who may be considering copy and pasting a method with their own adjustments to the code and doing things that will unintentionally break the inheritance chain.
 
You're also intending that your own code shouldn't be overridden, presumably, so I guess you'll also couple it with a super high execution order.
Exactly.

Thanks for the clarification, it's pretty much what I expected :)
 
Last edited:
Top Bottom