[ create a new paste ] login | about

Link: http://codepad.org/2MFm6lHr    [ raw code | output | fork ]

php.programmer - PHP, pasted on Apr 14:
<?php
// sample code to show the use of magic methods __construct and __destruct
// author@ : http://royads.blogspot.com

class parentClass
{
   function __construct()
    {
      echo "\nParent constructor called.";    
    } 

  function __destruct()
  {
    echo  "\ndestroying parent object";
  } 
}

class childClass extends parentClass
{
  function __construct()
  {
     echo "\nchild constructor called.";
     parent::__construct();
  }
  function __destruct()
  {
    echo  "\ndestroying child object";
    parent::__destruct();
  }
}
$obj = new childClass();
?>


Output:
1
2
3
4
5

child constructor called.
Parent constructor called.
destroying child object
destroying parent object


Create a new paste based on this one


Comments: