What Is Differences Between Objects And Classes In Php?
Moderator: General Moderators
-
phpdevelopers
- Forum Newbie
- Posts: 7
- Joined: Wed May 16, 2012 2:17 am
What Is Differences Between Objects And Classes In Php?
What Is Differences Between Objects And Classes In Php?
- 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?
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
- 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?
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.
- 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?
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.
An object is the actual data, so you can have many objects created from a single Class declaration.
(#10850)