Failover methods in ViewableData
are not cleared correctly when a new failover record is set
#11574
Labels
ViewableData
are not cleared correctly when a new failover record is set
#11574
Found in CMS 5 - presumably also affects CMS 6
The
SilverStripe\Core\Extensible
trait along with theSilverStripe\Core\CustomMethods
trait are responsible for allowing methods from extensions to be called on classes which have those extensions applied.ViewableData
has a concept of afailover
which allows one object to call methods from another object (e.g. call methods on a controller, and it will "failover" to calling methods on the data record the controller represents).These two things combine to create the following bug:
All methods available on a page are defined as "failover" methods on the page's controller. If a page class shares the same controller as another page class (e.g. two page classes both defaulting to use
PageController
), and Page A has methods which Page B doesn't have, and Page B is a child of Page A - thehasMethod()
method will returntrue
for methods from Page A even whenhasMethod()
is called on Page B's controller.This seems to be caused by the
$extra_methods
array being held statically (which is done for performance reasons) and not correctly clearing/removing methods out of that array when setting or removing a failover from a class.Related
__get
methods interfere with classes that share the same parent #10263Reproduction steps
Note that for steps 1 and 2 you can use the
BasicElementalPage
class provided by frameworktest.Page
. DO NOT give it its own controller class (i.e. it will fall back to usingPageController
)ElementalPageExtension
)Page
record. Publish it.templates/Page.ss
ortemplates/Layout/Page.ss
) call the method that exists on your new page type (in my case using the$ElementalArea
template variable)Note that viewing a
Page
record at the root level will not throw the exception. Only when the page is a child of the new class will it throw the exception.The text was updated successfully, but these errors were encountered: