What Is Differences Between Objects And Classes In Php?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
phpdevelopers
Forum Newbie
Posts: 7
Joined: Wed May 16, 2012 2:17 am

What Is Differences Between Objects And Classes In Php?

Post by phpdevelopers »

What Is Differences Between Objects And Classes In Php?
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: What Is Differences Between Objects And Classes In Php?

Post by social_experiment »

A class is a piece of code containing methods and properties. An object is a new instance of the class from where you can use the methods & properties in the class.
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Re: What Is Differences Between Objects And Classes In Php?

Post by Chris Corbyn »

This concept applies to all OO languages, not just PHP. A class is basically a description for what an object contains and does. To make the object (instance of the class) behave differently, you edit the code in the class.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: What Is Differences Between Objects And Classes In Php?

Post by Christopher »

It is important to remember that Objects are Data + Code. Think Data first -- a Class is a custom data type. A Class contains the variable declarations for the data and the code that operates on that data. So a class defines both how to declare the object's data and what operations can be performed on the data.

An object is the actual data, so you can have many objects created from a single Class declaration.
(#10850)
Post Reply