Example of inheritence

<?php

class site_user
{
public $name;
public $age;
public $profession;

public function setter($n, $a, $p)
{
$this->name = $n;
$this->age = $a;
$this->profession = $p;
}
public function show()
{
echo ‘Name :’.$this->name.'<br/>’.’Age :’.$this->age.'<br/>’.’Profession :’.$this->profession.'<br/>’;
}
}

class hacker extends site_user
{
public $hacked_site;
public $language;
public function setter ($h,$l,$n, $a, $p)
{
$this->hacked_site = $h;
$this->language = $l;
parent::setter($n, $a, $p);
}
public function show()
{

parent::show();
echo ‘Hacked Site :’.$this->hacked_site.'<br/>’.’Language :’.$this->language;
}
}

$user1 = new site_user();

$user1->setter(‘tanvir’,22,’student’);
$user1->show();

echo “<br/>”;
$user2 = new hacker();

$user2->setter(‘facebook’,’php’,’tanvir’,22,’student’);
$user2->show();
?>

in the above example , site_user is the parent class and hacker is child class ..

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s