Jump to content

Good programming practice


paul2010

Recommended Posts

Just a few questions about good programming practice in PHP coming from a Java background.

 

How important are getter and setter functions or is it acceptable to use to just have a variable set to public?

 

what is the scope of a variable inside  a private a function?

 

is it best to declare all variables as private and when using them inside a function use $this->name ?

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/227428-good-programming-practice/
Share on other sites

How important are getter and setter functions or is it acceptable to use to just have a variable set to public?

 

In any language it's better to provide a clear interface using methods rather than properties in my opinion.

 

what is the scope of a variable inside  a private a function?

 

Variables created within a function (or a method) are only available within said function.

 

is it best to declare all variables as private and when using them inside a function use $this->name ?

 

Often it is best to keep the inner workings of a class private. If you don't need access to the variable from outside of an object, it should be private. Even then, I would suggest still keeping variables private and creating getter setters.

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.