PHP constructor and destructor are special type functions which are automatically called when a PHP class object is created and destroyed. The constructor is the most useful of the two because it allows you to send parameters along when creating a new object, which can then be used to initialize variables on the object.
<?php class Foo
{ private $name; private $link; public function __construct($name) { $this->;name = $name;
}
public function setLink(Foo $link){
$this->;link = $link;
}
public function __destruct() {
echo 'Destroying: ', $this->name, PHP_EOL;
}
}
?>