Monday 8 February 2016

Constructor and Destructor in PHP

Code:

<?php
echo "<center><h1>Constructor and Destructor</h1>";
class book
{
    function __construct($p,$t)
    {   
        $this->price = $p;
        $this->title = $t;
        echo "title: $t <br/>";
        echo "price: $p <br/>";
        echo "Constructor working!<br/><br/>";
    }
   
    function __destruct()
    {
        echo "object Destroyed</center>";
    }
}
$book=new book("450","optics");
?>



Output:


No comments:

Post a Comment