-
Notifications
You must be signed in to change notification settings - Fork 825
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Magic __get
methods interfere with classes that share the same parent
#10263
Comments
Is |
That I'm not totally sure about to be honest, but it seems to come from: public function hasMethod($method)
{
return method_exists($this, $method) || $this->getExtraMethodConfig($method);
} calling (from protected function defineMethods()
{
$this->defineMethodsCustom();
// Define extension methods
$this->defineExtensionMethods();
} And it comes in through |
This is really confusing to follow. Do you have some actual minimal reproduction code you could share instead? So far I read into it what Loz has stated already. |
Sure thing. AndantePage.php
<?php
class AndantePage extends Page
{
private static $db = [
'Summary' => 'Varchar(255)',
];
} NightjarPage.php
<?php
class NightjarPage extends Page
{
public function getSummary()
{
return 'Nightjar in the day is just a Dayjar';
}
} AndantePage.ss
$Summary Expected result when visiting any old |
I can’t recreate this - I just get nothing rendered for |
Can't recreate this either on the latest release. |
How curious. I'll dig in a little and see if it's coming from somewhere else, though I'm pretty sure we aren't doing anything particularly weird in this project. Will see what exactly I need to set up to reproduce. |
If by the child you mean nested underneath, that could suggest it's related to the |
Yes that's right. I suspect something to do with Scope and Hierarchy and the magic that lets Controllers pull methods from their Pages. More investigation required, but at least I can reproduce it and am not losing my mind entirely. Yet. |
Had a quick look into this, I think the problem comes from the silverstripe-framework/src/Core/CustomMethods.php Lines 15 to 20 in 78c9aea
After the controller is built for the parent page, it looks (roughly) like this: $extra_methods = [
ContentController::class => [
'getSummary'
]
]; The second instance of I’m not really sure what the best solution here is. Sharing these methods statically probably isn’t a good idea, but I’d be wary about performance regressions from changing that |
Oh hey, that looks like #11574 |
Affected Version
4.10 (is what I've tested on)
Description
I have in my project a
Page
andPageController
(thanks, CMS)I have two Page types:
CoolPage extends Page
DopePage extends Page
CoolPage
has a$db
fieldSummary
DopePage
has a methodgetSummary()
Adding
$Summary
in myCoolPage.ss
throws the error:I've tracked this down to the
__get()
method onViewableData
, because the following line returnstrue
:Which is because
PageController::hasMethod('getSummary')
returnstrue
, as it's getting it fromDopePage
, but then it can't call it in the next line:because
CoolPage
, the current scope, doesn't.I've been able to work around this by creating an otherwise empty
CoolPageController extends PageController
, but that feels inelegant.The text was updated successfully, but these errors were encountered: