paul2010 Posted February 12, 2011 Share Posted February 12, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/227428-good-programming-practice/ Share on other sites More sharing options...
trq Posted February 12, 2011 Share Posted February 12, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/227428-good-programming-practice/#findComment-1173097 Share on other sites More sharing options...
paul2010 Posted February 12, 2011 Author Share Posted February 12, 2011 Thanks for your reply. Do variables need to be unset after they are finished with or will PHP do that automatically? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/227428-good-programming-practice/#findComment-1173103 Share on other sites More sharing options...
trq Posted February 12, 2011 Share Posted February 12, 2011 PHP will of course take care of that for you. I know of no language where you would need to do such a thing. Quote Link to comment https://forums.phpfreaks.com/topic/227428-good-programming-practice/#findComment-1173116 Share on other sites More sharing options...
paul2010 Posted February 13, 2011 Author Share Posted February 13, 2011 PHP will of course take care of that for you. I know of no language where you would need to do such a thing. I was hoping that would be the case. But I think that objective c likes you to release all variables as part of memory management? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/227428-good-programming-practice/#findComment-1173427 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.