1
2<?php
3class BaseClass {
4 function __construct() {
5 print "In BaseClass constructor\n";
6 }
7}
8
9class SubClass extends BaseClass {
10 function __construct() {
11 parent::__construct();
12 print "In SubClass constructor\n";
13 }
14}
15
16class OtherSubClass extends BaseClass {
17 // inherits BaseClass's constructor
18}
19
20// In BaseClass constructor
21$obj = new BaseClass();
22
23// In BaseClass constructor
24// In SubClass constructor
25$obj = new SubClass();
26
27// In BaseClass constructor
28$obj = new OtherSubClass();
29?>
30
31
1<?php
2class BaseClass {
3 function __construct() {
4 print "En el constructor BaseClass\n";
5 }
6}
7
8class SubClass extends BaseClass {
9 function __construct() {
10 parent::__construct();
11 print "En el constructor SubClass\n";
12 }
13}
1<?php
2/**
3 *Inheritance: It means accessing property of parent class from child class.
4 *
5 * */
6class Animal
7{
8 function __construct()
9 {
10 echo '<br>construct1';
11 }
12 function fun1()
13 {
14 echo '<br>fun1';
15 }
16}
17class Dog extends Animal
18{
19 function __construct()
20 {
21 // if want to call parent class constructor
22 parent::__construct();
23 echo '<br>construct2';
24 }
25 function fun1()
26 {
27 echo '<br>Dog class function called';
28 }
29}
30$obj = new Dog();
31$obj ->fun1();
32?>