PHP

How to demonstrate the default or no-argument constructor in PHP | PHP programs

How to demonstrate the default or no-argument constructor in PHP | PHP programs

How to demonstrate the default or no-argument constructor in PHP | PHP programs

We will create a class that contains the default or no-argument constructor, as we know that constructor of a class called automatically when the object of a class gets created.

<?php  

    class Sample
    {  
        public function  Sample()
        {  
            echo "Default constructor called<br>";  
        }  
        public function  Method1()
        {  
            echo "Method1 called<br>";  
        }  
    }  
    $S = new Sample();  
    $S->Method1();
?>
TutorialsLink Curator

This is an official account managed by the team TutorialsLink Community