Oops stands for Object Oriented Programming, In PHP it takes a major role in building a robust application. Not only PHP other languages like .Net, C#, JAVA, Python, etc. Oops, the concept takes a vital role to develop giant and secure applications or Mobiles apps, etc.
Class Concept in Opps – PHP
What is Class in Oops:-
A class is the blueprint of objects, or, we can say a data type that contains properties and methods.
Here is the below example, so you can have a clear idea about the class in PHP. In this example Car is the class name, and Price, Color, Brand are the member variable or properties, and setprice(), getprice(), setColor(), getColor(), setBrand(), getBrand() are the Member functions or methods.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | <?php class Car { /* Member variables */ var $price; var $color; var $brand; /* Member functions */ function setPrice($car_price){ $this->price = car_price; } /* Member functions */ function getPrice(){ echo $this->price; } /* Member functions */ function setColor($car_color){ $this->color = $car_color; } /* Member functions */ function getColor(){ echo $this->color; } /* Member functions */ function setBrand($car_brand){ echo $this->brand=$car_brand; } /* Member functions */ function getBrand(){ echo $this->brand; } } ?> |
Questions Asked In Interview About Class in Oops
- How many objects can Create in a Class
- What is a Class in PHP
- What is the Use of a Class in PHP
- What is an Abstract Class