Answers for "php parent construct"

PHP
6

php contruct parent

<?php
class BaseClass {
    function __construct() {
        print "In BaseClass constructor\n";
    }
}

class SubClass extends BaseClass {
    function __construct() {
        parent::__construct();
        print "In SubClass constructor\n";
    }
}

class OtherSubClass extends BaseClass {
    // inherits BaseClass's constructor
}

// In BaseClass constructor
$obj = new BaseClass();

// In BaseClass constructor
// In SubClass constructor
$obj = new SubClass();

// In BaseClass constructor
$obj = new OtherSubClass();
?>
Posted by: Guest on February-22-2020
1

php call parent constructor

<?php
class BaseClass {
   function __construct() {
       print "En el constructor BaseClass\n";
   }
}

class SubClass extends BaseClass {
   function __construct() {
       parent::__construct();
       print "En el constructor SubClass\n";
   }
}
Posted by: Guest on April-12-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

Browse Popular Code Answers by Language