Extending a Class in OOPHP

Hello Readers

Lest go to check, how to extend a class in Object Oriented PHP. It’ s very easy to make. One of the greatest features in OOP is that you can extend a class and create a completely new object. The new object can retain all the functionality of the parent object from which it is extended or can override. The new object can also introduce some features. Let’s extend our myClass class and override the myNewClass function so that it can send HTML mails.

First of all, create a file named class.extend.php and write these code into this file.

class myClass{
 public $name;
 public $address;
 public function myName($name, $address){
 echo $this->name = $name."<br>";
 echo $this->address=$address."<br>";

class myNewClass extends myClass {
 private $age;
 public function myProfile($a, $b, $age)
 $this->myName($a, $b);
 echo $this->age=$age;


//creating a object 
$user= new myNewClass();
$user->myProfile('Suchi', 'Uttara', 23);



Thanks to read. Take Care.


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 )

Google+ photo

You are commenting using your Google+ 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 )


Connecting to %s