View Single Post
Old 04-18-2009, 04:11 PM   #9 (permalink)
allworknoplay
The Gregarious
 
allworknoplay's Avatar
 
Join Date: Feb 2009
Location: New York
Posts: 645
Thanks: 64
allworknoplay is on a distinguished road
Default

Quote:
Originally Posted by Tanax View Post

Surely you can do them staticly, but remember you need to set the class variables to public then - which I strongly advice you not to do, 'cause then you can also accidently change the value aswell Classname::$variable = "bogus" which, needless to say, is quite a security issue.

It's safer to have a method instead to fetch a private classvariable, that way you can be sure that it's only able to return the current value, and never change it.

When/what is the appropriate time to ever set a property to "public" or is it never?


I like the idea of accessing a property value directly, it seems cleaner....or shorter than to have to create a "getter" method to get obtain the data value.

I can also see the security issue side of it, so I guess my question is:

1) why would PHP implement this if there are security issues?

2) is there ever an appropriate time set a property to public?
allworknoplay is offline  
Reply With Quote