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