18 Program to demonstrate Constructor in PHP.

Program:
<?php

    class Student

    {

        protected  $roll_no;

        protected  $name;

      

        function __construct()

        {

            $this->roll_no = 4;

            $this->name="Atharva";

        }

        function display()

        {

            echo "RollNo: $this->roll_no <br/>";

            echo "Name: $this->name <br/>";

        }

    }



    $s1 = new Student;



    $s1->display();

  

?>

Output:
Program to demonstrate Constructor and Destructor in PHP.

Previous
Next Post »