Follow us on Facebook
Faucibus toroot menuts
â€˜Small talkâ€™ was the first oop language
Java was the first popular Object oriented programing language
C++, java and c# are some of The popular programing languages
Object oriented feature came in php after version 5
Any programing language is said to be an OOPs( Object Oriented Programing System) programing language if it has following basic features:
Abstraction is the mechanism in which only the essential features are highlighted and unnecessary detail are hidden from users. For example, in a car the users are provided gear, accelerator, steering wheel etc . User does not need to know how the engine works . How the petrol is converted into electric etc. In programing world, software developer provides the user the user interface to handle the system. User need not know how the coding was done to work the system.
Encapsulate, to hide unnecessary details. For example In a capsule, the patient need not know what is inside the capsule. The patient sees the shinny capsule and does not know the bitter medicine which has been encapsulated.
In software world, database connection, security related code is encapsulated from the users so that it cannot be tempered with.
Take example of India women. She takes cares of he household work, she takes care of cooking, she takes care of children, she takes care of her office going husband. Etc. She is a single person but does different work as per situation
In Software world, when function name is same for but performs different task as per parameter, its called method overloading or polymorphism.
The process in which the child class inherits the data member of base class, its called inheritance.
When you think about a car, you think about whole general car. The car have some attributes and performs task. Its small whecile, its private man carrying whecile, it has four wheels, steering wheel etc. And it can run and honk etc.
So, all the cars having the above said common features will come under car class. So, class is a group of object which has common properties and behaviour(functions).
PHP Class Object
So, the car class Wireframe Model does not exist physically. Its just imaginary. This is just prototype.
What is a Class?
A group of objects which have common properties and behaviour, is called class.
So, lets get back to practical PHP world and write a simple code for a class.
What is an Object?
Object is an instance/example of class. Object is physical and we can touch it and work with it.
To run the car , the car must exists. We cannot drive with wireframe paper model car. Similarly, to access properties and methods of the class, we must create object first, only then we can access its behaviour.
Here we have created one object of car Class. So, we can access now properties and methods of car class.
The above properties and methods we can access through its object.
What is constructor?
Constructor is a special function which is automatically called when the object is created. To access other functions we have to create object first and then we can access the function specifically. But constructor can be called as soon as you create object.
PHP Class Inheritance
All Cars Inherits from same car Class but some cars have different design and additional functionalities.
For Example, BMWâ€™s car inherits all features of a normal car but its design is different from normal car and also it have AI features. For example, automatic break, finger touch door open etc.
Types of inheritance
PHP Static Keyword
When data member of any class is declared static, no object is needed to create to access these data members.Points to remember :
PHP Access Specifier
There are different level of data member accessing rules. So, with this example, I will try to explain how that works.
At airport of railway station, any user can use the WIFI. That means the wifi can be accessed by anyone.
All the family members can access the wifi in any certain room. So, in this scenario, we can say, the Home Wifi has â€˜Protected Accessâ€™
Your mobile can access internet only within your mobile and not outside.
So, in this scenario, we can say this is â€˜â€™ Private Accessâ€.
When base class and child class have same function name then child class overrides base class function and displays the child class function. This activity is called method overriding.
When functionâ€™s name is same but their signature(parameters) is different then its called method Overloading.
When same function performs different task based on parameters, can be termed as function overloading.
Whom is this tutorial for?
Steps to be followed