Jump to content

best designing class practices


stuffradio

Recommended Posts

is it pretty much standard(as far as i know) that members are remain private and you provide access methods(class functions) that can change them.  The reason for this is that you can control what can be done to the member so if you only want a number to be one member, you can make sure it will always be a number and so on.

True. It's a generic OO heuristic that "all properties should be private", but arguably it holds even more true for PHP classes, since PHP is loosely typed.

 

Sometimes protected is more appropriate, but I can't remember the last time I declared a property public.

I was taught that is C++ to show that the variable was an internal variable and not something being passed, I no longer do that in C++ anymore.  There is even less reason to do that is PHP since to access a class member to need to use the $this variable anyways but I guess it comes down to a matter of personal preferences, just like I would write:

 

function get_test_var();

function set_test_var(var);

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.