Welcome Guest, Not a member yet? Register   Sign In
To use variable accessors, or not to use, that's my question :)
#1

[eluser]RJ[/eluser]
I noticed most of CI code doesn't protect class variables and access with var accessors, is that the recommended way to go with CI?

Thanks
#2

[eluser]xwero[/eluser]
none of the class variables are protected or private because php4 doesn't support it.

You could make a distinction between public and protected class variables with an underscore prefix for the protected variables. This is in analogy with the hiding of controller methods but it doesn't do anything for the class variables.
#3

[eluser]RJ[/eluser]
Might I ask a stupid question of you; I understand how protected methods work, only available to the class they are a member of, but why protect a method at all?
#4

[eluser]xwero[/eluser]
So you can extend the method but not call it outside of the class. Basically it's a judgment call, do you trust future developers enough to call the method or do they have to extend them in order to keep the bugs/complains as low as possible. It's not a silver bullet solution but it can prevent new developers from tinkering too much.
#5

[eluser]RJ[/eluser]
ah, good thought.

Thank you much!
#6

[eluser]dmitrybelyakov[/eluser]
[quote author="bullspit" date="1239216366"]I noticed most of CI code doesn't protect class variables and access with var accessors, is that the recommended way to go with CI?

Thanks[/quote]

It is completely up to you. As in any other cases. I personally prefer to incapsulate class functionality and leave space for improvement and extension. If you use it you'll be surprised how useful it might appear when refactoring your code.




Theme © iAndrew 2016 - Forum software by © MyBB