Answers for "php destructor"

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
3

php __construct

public function __construct(){}
Posted by: Guest on October-03-2020
1

constructor and destructor in php

<?php
/*
    By defualt constructor call at the beginning and by defualt destructor call at the end.
    constructor and  destructor call automatic when object is called
*/
    class Birds
    {
        function __construct() 
        {
            echo "Start<br>";
        }
        function fun1() 
        {
            echo "this is function<br>";
        }
        function __destruct() 
        {
            echo "End";
        }
    }
    $parrot = new Birds();
    $parrot->fun1();
?>
Posted by: Guest on October-05-2021

Browse Popular Code Answers by Language