if want to call parent class constructor in php

Solutions on MaxInterview for if want to call parent class constructor in php by the best coders in the world

showing results for - "if want to call parent class constructor in php"
Aubin
04 Mar 2019
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?>