i
PHP Variables
PHP Data Types
PHP Echo & Print
PHP Strings
PHP Numbers
PHP Constants
PHP Operators
PHP if...else...elseif Statements
Switch Statement
PHP Loops
PHP Arrays
Superglobals
PHP Coding Standards
PHP Form Handling
PHP Form Validation
PHP URLs Validation
PHP Form Required Validation
Complete Form Example
PHP File Functions Open/Read
PHP File Create/Write
PHP File Upload
PHP Cookies Handling
PHP Session Handling
PHP filter_var() Function
PHP Validation Filters
PHP Sanitization Filters
Using Filters
Filters Advanced
JSON
PHP Date and Time
MySQL Database
MySQL Connect
MySQL Commands-Creating a Table
MySQL Commands-Inserting The data
MySQL Commands-Prepared Statement
MySQL Commands-Selecting The Data
MySQL Commands-Where and Order By
MySQL Commands-Deleting And Updating The Data
PHP-OOP Introduction
PHP-Classes/Objects
PHP-Constructor/Destructor
PHP-Access Modifiers
PHP-Inheritance
PHP-Inheritance and Protected Access Modifier
PHP-Overriding Inherited Methods
PHP-Final keyword
PHP-Abstract Classes
PHP-Constants
PHP-Traits
PHP-Static Methods and Properties
Introduction to Functions
Defining A function
Returning Values From A Function
Dynamic Function Calls
Variable Scope
Understanding Arguments Or Parameters
Testing For A Function Existence
Returning Multiple Values From A Function
Making practical Use By Building Code Libraries For Code Re-usability
Using Include() And Require()
As we discussed that a derived class can access protected properties and methods of the parent class. Let us see via example:
class Doctor {
public $name;
public function __construct($name) {
$this->name = $name;
}
protected function intro() {
echo "The Doctor name is {$this->name}
}"; } }
// Surgeon is inherited from Doctor
class Surgeon extends Doctor{
public function message() {
echo "The surgeon are doctors experienced in surgery";
}
}
$Surgeon1 = new Surgeon1("Sebastian"); //public construct function works fine.
$Surgeon1 ->message(); // public method works fine
$Surgeon1 ->intro(); // gives error as intro() is protected method in parent class.
?>
However, you can use the protected method inside a derived class as below:
class Doctor {
public $name;
public function __construct($name) {
$this->name = $name;
}
public function intro() {
echo "The Doctor name is {$this->name}
}"; } }
// Surgeon is inherited from Doctor
class Surgeon extends Doctor{
public function message() {
echo "The surgeon are doctors experienced in surgery";
$this -> intro(); // Calling protected method inside derived class works fine.
}
}
$Surgeon1 = new Surgeon1("Sebastian");
$Surgeon1 ->message(); // message is public and intro() inside message function is //used inside derived class. So, it works fine.
?>
Don't miss out!