This forum is in archive mode. You will not be able to post new content.

Author Topic: PHP - What are classes all about?  (Read 3946 times)

0 Members and 1 Guest are viewing this topic.

Offline m0l0ko

  • Peasant
  • *
  • Posts: 129
  • Cookies: -4
    • View Profile
PHP - What are classes all about?
« on: February 04, 2013, 01:19:31 AM »
I'm trying to learn the concept of classes so I'm looking for a reason to use them but I find the whole concept might confusing. I can't yet see why I would use a class instead of just using a function. I don't understand why in classes you assign variables that are either public, protected or private, how does assigning a private or protected variable have any advantage over a regular public variable?

Thats besides the point though, I'm trying to figure out situations in which I would need to use classes so I can start practicing with them and implementing them into my code.

Mike245

  • Guest
Re: PHP - What are classes all about?
« Reply #1 on: February 04, 2013, 01:53:07 AM »
Using classes and objects is all about proper Object Oriented Programming. They are used to structure your code and provide proper encapsulation. It also makes it easy to implement polymorphism. I have never done PHP though. The biggest reasons for using OOP is re-usable code and polymorphism.


I hope this helps.

Offline m0l0ko

  • Peasant
  • *
  • Posts: 129
  • Cookies: -4
    • View Profile
Re: PHP - What are classes all about?
« Reply #2 on: February 04, 2013, 03:10:32 AM »
I still don't understand when and where to use classes. My PHP scripts usually consist of a big page of functions, then a bit of code that calls the functions. What advantage would uses classes have over this? I notice you can put functions inside capsules which I like but I don't really know why I would wanna put functions inside a class.

Mike245

  • Guest
Re: PHP - What are classes all about?
« Reply #3 on: February 04, 2013, 03:24:52 AM »
Anytime you want to have data grouped together instead of having a mass of fuctions and global variables, use classes. It can also help with keeping code organized.


Classes help with organizing data and functions together.


I come from a background of strictly OOP. C#, Java, Objective-C. So it just comes naturally to me. I'm not sure how to better explain it though.

Offline proxx

  • Avatarception
  • Global Moderator
  • Titan
  • *
  • Posts: 2803
  • Cookies: 256
  • ФФФ
    • View Profile
Re: PHP - What are classes all about?
« Reply #4 on: February 04, 2013, 04:57:53 AM »

http://web.engr.oregonstate.edu/~budd/Books/oopintro3e/info/chap01.pdf

This is a snippet of some book about OOP in general.
Its funny how its uses ; the flower boy, the driver etc etc as examples.
Helped me to grasp the concept.


https://www.youtube.com/watch?v=tWIe9E4SWQo
This is fucking awesome.
« Last Edit: February 04, 2013, 05:12:09 AM by proxx »
Wtf where you thinking with that signature? - Phage.
This was another little experiment *evillaughter - Proxx.
Evilception... - Phage

 



Want to be here? Contact Ande, Factionwars or Kulverstukas on the forum or at IRC.