Javascript AJAX jQuery HTML OOPS PHP PHP Example MORE

PHP oops tutorial

OOPs stand for object oriented programming.

Object oriented is a method which can contain both data and method.

OOPs concept has several advantages :

  1. It is faster and easy
  2. It gives a clean structure of a program
  3. Reuse of code

Class:

Class is a collection of objects It doesn't take any spaces. Example: Bike, Car, Fruit

Object:

An entity that has state and behavior is known as an object e.g., chair, bike, marker, pen, table, Apple etc.

Example:

class

Bike

Objects

Kawasaki

Ducati

Harley-Davidson

Example

<?php
   class Bike {
      /* Member variables */
      var $price;
      var $title;
      
      /* Member functions */
      function setPrice($par){
         $this->price = $par;
      }
      
      function getPrice(){
         echo $this->price ."<br/>";
      }
      
      function setTitle($par){
         $this->title = $par;
      }
      
      function getTitle(){
         echo $this->title ." <br/>";
      }
   }
?>