Jump to content

Why use classes?


spyke01

Recommended Posts

Ok there will probally be much flaming about this, but here goes. ive seen many people using classes, but ive never used them simply because i dont see a reason to do it in my code. I have seen where people use it to access different style databses, kinda like phpbb does. ive programmed forums, content management systems, trouble ticket systems, and store systems but never once used a class. So heres my question, when(please use a real world example) would i really need to use them? how much more effecient is if to use a class instead of functions with global variables?
Link to comment
https://forums.phpfreaks.com/topic/15369-why-use-classes/
Share on other sites

The larger the project, the more global variables and functions collide. What if you wanted to use a friends code that had a bunch of global variables that overwrote yours? I haven't done a lot of OPP, and the little I have done has been in Perl, not PHP. Before I understood what it was, I had the same notion as you--What's the point? This is understood in time. Any basic OPP primer should lay out the advantages for you, such as abstraction and inheritance. I see it as a containment system. You have your own "namespace" in which you cannot run into anyone else, and you can also control what the user can and cannot do within this area--private or public methods, e.g.
Link to comment
https://forums.phpfreaks.com/topic/15369-why-use-classes/#findComment-62280
Share on other sites

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.