PHP OBJECT
An objects is an enclosed bundle of variables and functions forged from a special
templates called classes.Objects hide lot of their inner working away from the code that uses them,providing instead
easy interfaces through which can send them orders and they can return information.These interfaces are special functions called methods.
Classes is a collection of special functions called methods. and special variables called properaties. You can declare classes with classes keyword. Classes are the objects from which objects are created.
CREATING AN OBJECT
To create an object you must first design the template form which it can be instantiated.The temaplte is known as classes.
objects have access to special variables called properaties. these can be declared anywhere within the body of your class,but for the sake of clarity should be defined at the top.a property can be a value an array or even another objects.
example
class fisrt_class
{
var $name="webschool";
}
Notice that we declared our variables with var keywors.this is essential in the context of a class.now any first_class object is ctreated contain a property called name with the value of webschool. You can access this property form the outside the object and even change it.
example
The -> operator allows you to access or change the properties of an object.
|
object methods example
| output hello
|
|
|
output
hello welcome to myschool which is webschools
|
|
changing the value property within a method
| output
hello welcome to myschool which is ITschool |
|