Declaring and Using Object Constructors and Destructors : Destructors « Class « PHP






Declaring and Using Object Constructors and Destructors

 
<?php
class cd {
    public $artist;
    public $title;
    protected $tracks;
    private $disk_id;

    public function __construct() {
        $this->disk_id = sha1('cd' . time() . rand());
    }
    public function get_disk_id() {
        return $this->disk_id;
    }
}

$mydisk = new cd();
echo $mydisk->get_disk_id();
?>
  
  








Related examples in the same category

1.destuctor in action
2.Class destructors
3.Accessing instance-specific data within a destructor
4.Class with destructors
5.Cleaning Up with the __destruct Method (PHP 5 Only)
6.Defining an object destructor