Concept
The basic idea behind this concept is when declaring classes, it's also possible
to separate functionality into subclasses that automatically inherit the methods
and variables of the class on which they are based. This can be useful if you're
adding functionality to a class without modifying the original class.
The extends operator
When a class inherits from another class, the class from which it inherits
is called the super class. When declaring a subclass, use the extends
keyword to specify from which class it's inheriting.
Script for Inheritance PHP
<html>
<body
bgcolor="cyan">
<center>
<h3>
Inheritance with PHP
<h3>
<hr>
<?php
class
Mike {
// How old
the Mike is
var
$age;
function
mike($new_age)
{
// Set the
age of Mike to the n
$this->age = $new_age;
}
function
Birthday(){
$this->age++;
}
}
class
MikeSte
extends
Mike {
//
Constructor
function
MikeSte()
{
}
// Sleep
like a Mike
function
sleep() {
echo("Mike
is Presenting a inheritance with PHP.<br />");
}
}
$fluffy=new
MikeSte();
$fluffy->Birthday();
$fluffy->sleep();
echo
"Mike Age
is
$fluffy->age
<br />";
?>
</center>
</body>
</html>
Saved it by ext.php
Output of above script
To run the code, Open the XAMPP server and start the services like Apache and
MySQL. Open the browser type: http://localhost/yourfoldername/ext.php

The Parent Operator
Here in this section we will understand the inheritance with the parent
operator, When extending classes to override functions in your class that are
already defined in the super class, you can still execute the code from the
parent class and then add on your own functionality.
Syntax
parent::method_from_parent
Join the conversation! Your thoughts help the community grow.