Jump to content


Photo

Why use classes?


  • Please log in to reply
2 replies to this topic

#1 spyke01

spyke01
  • Members
  • PipPipPip
  • Advanced Member
  • 74 posts

Posted 23 July 2006 - 02:26 AM

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?

[a href="http://www.fasttracksites.com" target="_blank"]Cheap PHP Hosting[/a]

#2 Branden Wagner

Branden Wagner
  • Members
  • PipPipPip
  • Advanced Member
  • 111 posts

Posted 23 July 2006 - 02:28 AM

well if your like me you started out with Java, and then learned PHP soooo its a habit.
but ive always wondered the same thing.. is there a reason? so far all ive found out it that its a matter of habit.

#3 effigy

effigy
  • Staff Alumni
  • Advanced Member
  • 3,600 posts
  • LocationIL

Posted 23 July 2006 - 02:31 AM

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.
Regexp | Unicode Article | Letter Database
/\A(e)?((1)?ff(?:(?:ig)?y)?|f(?:ig)?)\z/




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users