-
Notifications
You must be signed in to change notification settings - Fork 75
Allow to set undefined properties in yii\base\Object #41
Comments
@berosoboy commented on Mar 7, 2018, 2:13 PM UTC: You can create your custom Object class that extends yii\base\Object and overrides the __set with your proposed code:
And your custom classes can extends your custom Object. |
@samdark commented on Mar 7, 2018, 6:27 PM UTC: OK. Let's have another look at it. Yii indeed enhances default PHP objects behavior adding several features:
On top if it, Component adds:
Ideally we want to divide these into traits and be able to use any combination of these traits for any object. The problem is that same |
@samdark commented on Mar 7, 2018, 8:59 PM UTC: We could probably add a specialized trait that could be configured with an array of handlers for the purpose but I do not see any way for it to be as performant as current solution. |
@mikehaertl commented on Mar 8, 2018, 7:28 AM UTC: I don't know a perfect way either. Each thinkable solution has shortcomings. Still, my current favourite is having a (optional!!) class property like:
Only if defined this would disable checks for existing properties. The default would be the same behavior we have now. |
@mikehaertl commented on Mar 8, 2018, 7:34 AM UTC:
berosoboy Sure, but I may also want to extend a more complex Yii class and still disable that behavior. With your suggestion I'd basically end up duplicating a lot of Yii classes in that case. |
@SilverFire commented on Mar 8, 2018, 9:07 AM UTC: I'd rather see it as |
@mikehaertl commented on Mar 8, 2018, 9:54 AM UTC: SilverFire You mean an empty interface ( |
There will be no yii\base\Object in Yii 3.0. |
@mikehaertl commented on Mar 7, 2018, 11:28 AM UTC:
I have to come back to my closed issue #12021. It seems that this is still not fixed in Yii 2.1.
My description and use case there is still valid.
The outcome of #12021 was, that this should be implemented via a trait. But it seems this never happened in 2.1.
tl;dr: I want to use the magic getter/setter methods from
yii\base\BaseObject
to be available in my custom classes. But I don't want that this changes PHP's default behavior, where you can also set undefined properties on a class.Yii changes this default behavior of PHP:
This issue was moved by samdark from yiisoft/yii2#15845.
The text was updated successfully, but these errors were encountered: