1
kaotik
php5 public/private methods, pros cons
  • 2006/12/19 11:01

  • kaotik

  • Just can't stay away

  • Posts: 861

  • Since: 2004/2/19


I've been reading about private/public/protected classes in php5. By protecting a particular function inside a class with private, outside access to this function will no longer be available. My question is; is it simply an extra layer of security?
www.kaotik.biz

2
Mithrandir
Re: php5 public/private methods, pros cons

Security? Not in the traditional sense of security against malicious hackers.

Private/protected does ensure that the particular method or attribute cannot be used outside the class/child classes and it can help make sure that it is only called by your code or by code that extends your code.

For example (don't know how appropriate), since we want the vars on a XoopsObject to go through setVar() or getVar(), we could make the $vars attribute private in the XoopsObject class. Anyone wanting to change or retrieve an attribute will have to go through setVar() and getVar() and we should be safe from rogue code modifying attributes directly (and potentially incorrectly). Of course, this particular "problem" can also be solved with __get() and __set() methods.
"When you can flatten entire cities at a whim, a tendency towards quiet reflection and seeing-things-from-the-other-fellow's-point-of-view is seldom necessary."

Cusix Software

Login

Who's Online

277 user(s) are online (185 user(s) are browsing Support Forums)


Members: 0


Guests: 277


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: May 31
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits