You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Considering the ComponentWithFormTrait we can notice there are few private methods. In general, it's not messing anything up, but when we deal with projects like Sylius, it becomes problematic.
We have a FormComponent class using ComponentWithFormTrait.
We want to override some behavior or FormComponent by extending it. Let's call it a BetterFormComponent.
We need to add use ComponentWithFormTrait inside the BetterFormComponent as they're private (we cannot access them nor use e.g. formValues.
And yes, it can be easily done by a use statement; however (real case), I had an overridden trait's method in the parent class, and I couldn't find why my component is misbehaving compared to the original one :P.
So my suggestion is to mark all private methods in this trait as protected. It seems it wouldn't come with any side effects.
The text was updated successfully, but these errors were encountered:
And yes, it can be easily done by a use statement; however (real case), I had an overridden trait's method in the parent class, and I couldn't find why my component is misbehaving compared to the original one :P.
I'm not 100% sure to understand, but the following code won't work as you want?
class FormComponent {
use ComponentWithFormTrait { thePrivateMethod asprotected; }
}
class BetterFormComponent extends FormComponent {
// ...
}
Kocal
changed the title
[Live Component] Fix methods visibility
[LiveComponent] Fix methods visibility
Jan 19, 2025
Hmm... as much as I understand your situation, this is exactly what private properties / methods ... protect us from.
Let me explain :)
Due to the Symfony BC promise, as long methods are private, we can do things (not all, but still have some freedom to recode things and / or improves them..)
But anything protected cannot be touched anymore in interface / behaviour / signature / etc.... for many years.
And this is not something we should risk.
... and not something we can do without opening BC for existing users :)
Hello,
Considering the
ComponentWithFormTrait
we can notice there are fewprivate
methods. In general, it's not messing anything up, but when we deal with projects like Sylius, it becomes problematic.FormComponent
class usingComponentWithFormTrait
.FormComponent
by extending it. Let's call it aBetterFormComponent
.use ComponentWithFormTrait
inside theBetterFormComponent
as they're private (we cannot access them nor use e.g.formValues
.And yes, it can be easily done by a
use
statement; however (real case), I had an overridden trait's method in the parent class, and I couldn't find why my component is misbehaving compared to the original one :P.So my suggestion is to mark all
private
methods in this trait asprotected
. It seems it wouldn't come with any side effects.The text was updated successfully, but these errors were encountered: