Yii Framework Forum: Private properties - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Private properties

#1 User is offline   dyulax 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 21
  • Joined: 26-May 11
  • Location:Brazil

Posted 16 November 2011 - 10:39 AM

I had a lot of trouble to extend classes with private attributes. May be it is a good idea to use protected ones instead.
Do what thou wilt shall be the whole of the Law.
1

#2 User is offline   samdark 

  • Having fun
  • Yii
  • Group: Yii Dev Team
  • Posts: 3,782
  • Joined: 17-January 09
  • Location:Russia

Posted 16 November 2011 - 04:21 PM

It was discussed several times already and we're generally agree with Symfony2 team on this matter http://fabien.potenc...cted-vs-private If you have case when you absolutely can't live with private members, post it as a bug and we'll try to fix it.
Yii 1.1 Application Development Cookbook

Enjoying Yii? Star us at github: 1.1 and 2.0.
2

#3 User is offline   Psih 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 115
  • Joined: 30-June 10

Posted 17 November 2011 - 03:31 AM

View Postsamdark, on 16 November 2011 - 04:21 PM, said:

It was discussed several times already and we're generally agree with Symfony2 team on this matter http://fabien.potenc...cted-vs-private If you have case when you absolutely can't live with private members, post it as a bug and we'll try to fix it.

Agree with samdark. Private properties are there for reason. If you have some specific case - it can be looked upon and decided to change the visibility if it is reasonable.
Making everything protected isn't good because then people can extend classes the way they want and break internal framework API's.
0

#4 User is offline   samdark 

  • Having fun
  • Yii
  • Group: Yii Dev Team
  • Posts: 3,782
  • Joined: 17-January 09
  • Location:Russia

Posted 17 November 2011 - 06:25 AM

Moreover if everything will be protected, we, as core framework developers, wouldn't have any chance to change internal things since it will break someone's code. So either Yii will break BC every release or will be kinda stucked in terms of improvements.
Yii 1.1 Application Development Cookbook

Enjoying Yii? Star us at github: 1.1 and 2.0.
2

#5 User is offline   Ben 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 274
  • Joined: 15-March 09

Posted 17 November 2011 - 09:32 AM

One problem I ran into several times: I try to extend a class, to override a public or protected method but can't, because the original method accesses some private members. Something I can't do in my override. Of course, it's not a problem as long as your override can call the parent's implementation. But if you don't want to do this - for whatever reasons - you're stuck.

I don't know a general solution for this, but maybe it's worth to keep an eye on it. I'll try to post an example if I come across such a problem again.
Don't like ads in my sig...
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users