Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Use of classes and security issue

Use of classes and security issue

Use of classes and security issue

So, I read an article that says that one should "never" directly invoke the value of a class object/variable like so


echo $object->variable; 

but rather have a method in the class and use the method to invoke the variable


function getValue($varName) {

and you will then call it like so


echo $object->getValue('variable'); 

Frankly, this looks like a big waste and seems like bloated coding. I love using classes to retrieve MySQL data from tables and fill forms/values and I have gotten my own approach that works for me ...

Now, security is something I take seriously and if using classes and invoking its variables ($object->variable) is risky, I will change my ways but hell, I really want to know if this is as bad as the guy in the article made it sound.

NOTE: I tried to dig up the article again to provide you guys the link but I just cannot find it.

The good thing about not knowing is the opportunity to learn - Yours truly, 2008.

RE: Use of classes and security issue

Generally speaking, unless you expect someone else to be using your code, it really does not matter all that much.

Private and Public variable distinction only comes into play if more than one person is modifying the code and will be using your classes to make other classes and you want to prevent modification of certain variable values directly from children classes. It also depends largely on what the variable will be used for within the class.

You may want to make some variables private and require a function to change from outside the class, since private variables cannot be directly modified from outside their containing object. If you need to control their value very tightly for some reason, like configuration variables for your application. Others may be left to be changed easily and directly if their purpose demands they are changed this way.

As an example, you may read some configuration file for your app settings, and want to keep certain variables from being modified later down the code so as to not alter those loaded settings directly. i.e Prevent Settings from being changed programmatically and only by editing the config file.

Otherwise, determining what you will allow to be accessed directly and what may not be accessed directly comes down to what you are doing with the variables. And if anything may be done with the classes further down the inheritance line.

Phil AKA Vacunita
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Web & Tech

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close