With inheritance create child classes that are based on the parent class. A child class inherits all the properties and methods of its parent and method.

Syntax:-

<? PHP

Class ClassBlogNameA

{

// (General properties and methods here)

}

Class ClassBlogNameB extends ClassBlogNameA

{

// (properties and methods here)

}

?>

Example:-

<?php

class ClassBlog

{

public $BlogVariable;

public $BlogName;

public function __construct($BlogVariable, $BlogName=NULL)

{

$this->BlogVariable = $BlogVariable;

if($BlogName)      {

$this->BlogName = $BlogName;

}

}

}

class ClassBlog extends ClassB

{

public $furColor;

public $legs;

function __construct($furColor, $legs, $BlogName=NULL)

{

parent::__construct(“warm”, $BlogName);

$this->furColor = $furColor;

$this->legs = $legs;

}

}

class ClassD extends ClassBlog

{

function __construct($furColor, $BlogName)

{

parent::__construct($furColor, 4, $BlogName);

self::b();

}

function b()

{

print(“$this->BlogName says ‘woof!'”);

}

}

$d = new ClassD(“Black and Tan”, “Angus”);

?>

 

Categories: PHP

0 thoughts on “PHP Class Inheritance”

Leave a Reply

Latest Article

Blog

PHP Magic Methods

__get()/__set() – These are magic getters and setters for getting and putting values for class properties created dynamically. __isset() – This magic method will be invoked automatically while checking whether a required overloaded property is Read more…

Blog

WordPress Upgrade

The WordPress upgrade released time to time. We provide a WordPress upgrade, content management and maintenance services at affordable price. WordPress upgrade fixes bugs, runs cleaner, faster, and is more secure and stable. We will Read more…

Blog

Magento 2 Upload image in product

If you are trying to upload image on respective product by script then below code will help you to solve this issue. by this code you can set product thumbnail, small and large image. $objectManager Read more…