Author: ShairyPortfolio
-

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
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
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”; }…
-

PHP Classes and Objects
Create a Course class for student that display their course code and subject enrolled from an institute. Explanation Properties: course code => 101 => int datatype subject => PHP => string datatype Methods: GetData () showData () Solution The $this is in-built or self-referencing variable which refers to the current object Way 1: Define variable…