Too Much Privacy

While developing apps, tweeking some Yii features I sometimes hit the wall becouse class properties are PRIVATE. I know that sometimes it’s good to hide some parts from newbies, but… Recently I had to write my own ActiveRecord class (copy yii’s one and change the code) becuse extending CActiveRecord wouldn’t work in my case.

So it would be great seeing most of private properties replaced with PROTECTED. It would make yii apps much more customizable.

As discussed many times about this… if you have a need for any private variable to become protected or private you just need to open a new github issue and explain your use-case - https://github.com/yiisoft/yii/issues/new

I understand current changes policy, however while Yii 2 is being developed, let it be another signal to consider rather protected than private properties and methods.

In my opinion framework should be easy to modify by default. Private class elements deny it, so I think such denial should be considered throughout and done when absolutely necessary only.

Sincerly I barely see good reason to block ability to extend class functionality in derived classes.

in many cases it is essential hence accessing some member variables directly can easily break the framework. It might seem easier to directly modify a private member variable but for the sake of code consistency it’s imperative that it should be done through some public or protected function calls. Private is not there to protect from newbies. Private is there to prevent breaking important functionality. Don’t confuse private declarations with the complete absence of operators overloading people encounter in Java just because of some really interesting overloading implementations seen in the past in C++. For example, overloading the + operator to initialise the database connectivity :blink:

(sorry for the irrelevant Java/C++ part… it’s just the eternal pain)

However, it would be magnificent to see the tight coupling break into loose coupling in Yii2 (something which I’ve heard was in the works since the beginning of Yii2 :D )

Have a nice day!! :)

I’m just curious: how does yii2 employ loose coupling? (Without having the time to delve into Yii2 at the moment ;-))

I ran into that problem too. Don’t private variables in fact impede OOP because you just can’t subclass without messing with main framework classes?

To make a point here: If you take a look at high level languages or mobile operating systems (android), they all do “protect” the developer from doing things that may break the thing. However, IF you really know what you do, it’s incredible hard to do it.

I.e. if you don’t want to use the default way (on android: java), it’s hard. And because it’s that hard, you will make more faults.

(private vs. protected isn’t something you’ll stumble upon and make faults. However, I don’t agree with your philosophy ;-))

Regards,