Tag: php

  • PHP Inheritance

    PHP Inheritance

    Way1 to inherit one class from another using the keyword extends <?php class Course{                 protected $courseCode;                 public function getCode($newCourseCode)                 {                                 $this->courseCode=$newCourseCode;                 } } class Subject extends Course{                 protected $subjectName;                 public function getCourse($newSubject)                 {                                 $this->subjectName=$newSubject;                 }                 public function showCourse(){                                                 echo “Student enrolled for <b>”.…

  • PHP Abstraction

    PHP Abstraction

    Code below defined an TV class. We cannot do much with it except turning it on and off. The class TV is an abstraction of a real TV in a very simple use case. <?php class TV {       private $isOn = false;       public function turnOn() {             $this->isOn = true;                }      public function turnOff()…

  • PHP Encapsulation

    PHP Encapsulation

    Encapsulation is used to bind the data using get and set method or hide the values to prevent from unauthorized parties’ to directly access them. For encapsulation, we generally use the concept of visibility (public, private, protected). Public Access <?php class Course{             public $subject;             public function getSubject()               {                         return $this->…

  • PHP Constructor & Destructor

    PHP Constructor & Destructor

    Create a Course class for student that display their course code and subject enrolled from an institute. Explanation Way 1: <?php class Course{             public function __construct()             {                         echo “The class “. __CLASS__.” was initiated<br>”;             }             public function __destruct()             {                         echo “The class “. __CLASS__.” was destroyed”;             }…