Destuctor In Action

 
    <?php
class Person {
    protected $name;
    private $age;
    private $id;        function __construct( $name, $age ) {
        $this->name = $name;
        $this->age  = $age;
    }    function setId( $id ) {
        $this->id = $id;
    }
 
    function __destruct() {
        if ( ! empty( $this->id ) ) {
            print "saving person\n";
        }
    }
}$person = new Person( "Joe", 31 );
$person->setId( 111 );
unset( $person );?>

Enjoyed this post? Share it!

 

Leave a comment

Your email address will not be published.