Day 7 at rtCamp
PHP OOP
- OOP stands for Object Oriented Programming. OOP is more focused on writing classes and functions in it and creating objects that has access to both data and functions.
- Following are some advantages of OOP
- Faster and easier to execution
- Helps to keep the PHP code DRY
Don't Repeat Yourself
- Here class is template of object and object is instance of class
class Person {
public $name;
public $age;
function setName($name) {
$this->name = $name;
}
function getName() {
return $this->name;
}
}
$john = new Person();
$john->setName('John');
echo $john->getName();
Constructor & Destructor
Constructor
- Constructor allows initialize an object properties upon creation of the object.
- In php
__construct()
function used to create constructor
class Person {
public $name;
public $age;
public function __construct($name, $age) {
$this->name = $name;
$this->age = $age;
}
}
$john = new Person('John', 18);
echo $john->name;
echo $john->age;
Destructor
- Destructor is called when the object is destructed or the script is stopped.
- In php
__destruct()
function is used to create a destructor __destruct()
is automatically called when script ends- Destructor can be used to release some resource and close IO or database connections
class Person {
public $name;
public $age;
public function __construct($name, $age) {
$this->name = $name;
$this->age = $age;
}
public function __destruct() {
echo "Releasing resources";
}
}
Access Modifiers
- PHP provides following access modifiers which controls where the properties and functions are accessible
public
: can be accessed from everywheredefault access specifier
protected
: can be accessed within the class and by classes derived from that classprivate
: can only be accessed within the class
Other
-
Screenshots of
Github Timeline
assignment -
Subscribe page
-
Verify OTP page
-
Received OTP on the email
-
Subscription confirmation
-
Subscription confirmation email
-
Github timeline updates after each 5 minutes on email
-
Option to unsubscribe
-
Unsubscription confirmation