Answers for "php get parent class variable"

PHP
1

if want to call parent class constructor in php

<?php
/**
 *Inheritance:  It means accessing property of parent class from child class.
 * 
 * */
class Animal
{
    function __construct()
    {
        echo '<br>construct1';
    }
    function fun1() 
    {
        echo '<br>fun1';
    }
}
class Dog extends Animal
{
    function __construct()
    {
        // if want to call parent class constructor 
        parent::__construct();
        echo '<br>construct2';
    }
    function fun1()
    {
        echo '<br>Dog class function called';
    } 
}
$obj = new Dog();
$obj ->fun1();
?>
Posted by: Guest on October-05-2021
0

parent in php

parent:: is the special name for parent class which when
  used in a member function.To use the parent to call 
  the parent class constructor to initialize the parent class so that 
  the object inherits the class assignment to give a name. 
    NOTE: PHP does not accept parent as the name of a function.
Posted by: Guest on July-12-2021

Code answers related to "php get parent class variable"

Browse Popular Code Answers by Language